我编写的第一个应用程序有问题。我在 YouTube 上观看了关于如何让用户注册 Firebase 并选择个人资料照片的教程。在视频中一切正常,但在我的项目中它给了我以下错误:
Value of type 'StorageReference' has no member 'put'
我已经看过关于这个主题的帖子,但我不喜欢那里给出的这个答案 (Value of type 'StorageReference' has no member 'put')。
这是我的完整代码:
let uploadTask = imageRef.put(data!, metadata: nil, completition: { (metadata, error) in
if err != nil{
print(err!.localizedDescription)
}
imageRef.downloadURL(completion: { (url, er) in
if er != nil{
print(er!.localizedDescription)
}
if let url = url {
let userInfo: [String: Any] = ["uid" : user.uid,
"full name" : self.nameField.text!,
"urlToImage" : url.absoluteString]
self.ref.child("users").child(user.uid).setValue(userInfo)
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController
(withIdentifier: "userVC")
self.present(vc, animated: true, completion: nil)
}
})
})
错误出现在第一行。
最佳答案
根据documentation以及您链接的问题,最新版本的 Firebase 使用 putData
,而不是 put
。
let uploadTask = imageRef.putData(data!, metadata: nil) { (metadata, error) in
// your code here
})
关于swift - FIREBASE 4 类型 'StorageReference' 的值没有成员 'put',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48772931/