“StorageReference”类型的值没有成员“数据”

时间:2017-06-30 06:02:37

标签: ios swift xcode firebase firebase-storage

这个代码几个月前就已经运行了,我已经在GitHub上检查了一些其他代码,并验证了这段代码在过去是否有用,但我找不到解决方案。我已经找到了使用Firebase Migration Support的解决方案,但我没有运气。提前谢谢!

    func configCell(searchDetail: Search) {

    self.searchDetail = searchDetail

    nameLbl.text = searchDetail.username

    let ref = Storage.storage().reference(forURL: searchDetail.userImg)

    //Error Below, highlighting 'ref.data' Error: Value of type 'StorageReference' has no member 'data'. 

    ref.data(withMaxSize: 1000000, completion: { (data, error) in

        if error != nil {

            print(" we couldnt upload the img")

        } else {

            if let imgData = data {

                if let img = UIImage(data: imgData) {

                    self.userImage.image = img
                }
            }
        }

    })
}

1 个答案:

答案 0 :(得分:7)

从您添加的迁移指南中,您现在需要使用新的getData(maxSize:completion:)代替data(withMaxSize:completion:)。所以就这样吧。

ref.getData(maxSize: 1000000, completion: { (data, error) in

    if error != nil {

        print(" we couldnt upload the img")

    } else {

        if let imgData = data,let img = UIImage(data: imgData) {
            self.userImage.image = img
        }
    }

})