使图像恢复火力迅捷时出现错误

时间:2019-04-18 07:16:59

标签: swift firebase

please check my image for storing and retrieving data enter image description here

我收到错误消息是因为我想从Firebase检索图像,我的url是字符串,但是有关uiImage的错误状态不能是字符串,是否可以得到显示的uiImageView图像。

顺便说一下,这是我下面的用户模型视图类         类用户{

    var username:String!
    var userage:String!
    var uid:String!
    var profileImageUrl: String!


    init (uid:String,dictionary:Dictionary<String,AnyObject>) {

    self.uid = uid
    if let username = dictionary [ "userName" ] as? String{

        self.username = username
    }

    if let userage = dictionary [ "useAge" ] as? String {

        self.userage = userage
    }

   if let profileImageUrl = dictionary["profileImageUrl"] as? String

 {

      self.profileImageUrl = profileImageUrl
   }


 }

    }

1 个答案:

答案 0 :(得分:0)

如果user.profileImageURL实际上是URL,则必须下载图像并将其分配给self.swipeLabel.image

要从URL下载图像,请参阅此帖子:Create a UIImage with a URL in iOS

如果图像已经存储,请使用以下代码。

self.swipeLabel.image = UIImage(contentsOfFile: profileimageurl)