【问题标题】:Initializer for conditional binding must have Optional type, not '() -> Data?'条件绑定的初始化程序必须具有 Optional 类型,而不是 '() -> Data?'
【发布时间】:2018-11-20 15:07:38
【问题描述】:

我遇到了一个问题,我想将图像上传到 Firebase 存储/数据库。当我创建这行代码时,我收到了这个问题:

if let uploadData = UIImage.pngData(self.profileImage.image!) {
}

此行的错误如标题所述:条件绑定的初始化程序必须具有 Optional 类型,而不是 '() -> Data?'

对如何解决这个问题有什么建议吗?

【问题讨论】:

    标签: ios swift uiimage


    【解决方案1】:

    你可以试试

    guard let uploadData = profileImage.image?.pngData() else { return }
    

    如果需要的话让

    if let uploadData = profileImage.image?.pngData() {
    
    } 
    

    pngData()UIImage实例的实例方法

    https://developer.apple.com/documentation/uikit/uiimage/1624096-pngdata

    在您的代码中,您认为它是不正确的类方法

    【讨论】:

      猜你喜欢
      • 2015-10-19
      • 2016-09-15
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 2021-04-26
      • 2016-01-27
      • 2018-03-05
      • 1970-01-01
      相关资源
      最近更新 更多