转换为最新的Swift语法后出错

时间:2016-02-07 18:12:19

标签: swift

我刚刚下载了Incognito starter project,在我打开它之后,我将其转换为最新的Swift语法,因为选项就在那里。之后我收到了linker command failed with exit code 1 (use -v to see invocation)的错误,我尝试使用here中的建议进行修复。它帮助我修复了错误。然后还有另外两个错误:

value of optional type 'NSData?' not unwrapped, did you mean to use '!' or '?'

和此:

value of optional type 'CGContext?' not unwrapped, did you mean to use '!' or '?'

对于此功能:

  func snapshot() -> NSData {
    UIGraphicsBeginImageContext(self.view.frame.size)
    self.view.layer.renderInContext(UIGraphicsGetCurrentContext())
    let fullScreenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil)
    return UIImageJPEGRepresentation(fullScreenshot, 0.5)
  }

在听完构造函数并修复它之后,结果是:

  func snapshot() -> NSData {
    UIGraphicsBeginImageContext(self.view.frame.size)
    self.view.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    let fullScreenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil)
    return UIImageJPEGRepresentation(fullScreenshot, 0.5)!
  }

但是现在我得到了和开头一样的错误:

linker command failed with exit code 1 (use -v to see invocation)

任何帮助都会非常感激!

0 个答案:

没有答案