【问题标题】:FIREBASE 4 Value of type 'StorageReference' has no member 'put'FIREBASE 4“StorageReference”类型的值没有成员“put”
【发布时间】:2018-07-24 04:25:56
【问题描述】:

我写的第一个应用程序有问题。我在 YouTube 上观看了有关如何让用户注册 Firebase 并选择个人资料图片的教程。在视频中一切正常,但在我的项目中,它给了我以下错误:

“StorageReference”类型的值没有成员“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)
                        }

                    })

                })

错误出现在第一行。

【问题讨论】:

  • 根据您链接的重复问题:put(data!...) => putData(data!...) 另外,如果您只写put,自动补全对您有帮助吗?
  • 不幸的是没有:-(我尝试了几乎所有找到的解决方案,但没有任何帮助,所以我需要再次询问。

标签: swift firebase


【解决方案1】:

根据documentation 和您链接的问题,最新版本的Firebase 使用putData,而不是put

let uploadTask = imageRef.putData(data!, metadata: nil) { (metadata, error) in

  // your code here

})

【讨论】:

  • 它仍然给我和以前一样的错误,还有一些新的错误说“'err'不可用:可变参数函数不可用”:-(
  • 是的,你在函数中称它为error,但随后在函数体中将它称为err
  • 哦,你是对的 - 但我仍然遇到与开始时相同的错误。
  • 非常感谢 - 我只需重写此文件中的所有内容就可以了 :-)
猜你喜欢
  • 2017-10-21
  • 2020-09-09
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-21
相关资源
最近更新 更多