unarchiveFromFile函数在下面的情况下不起作用。我有一个错误说:
"在预期返回的函数中缺少返回' SKNode?'
不确定是什么问题,因为在我将XCode更新到版本7.2之前,此功能正在运行。
extension SKNode {
class func unarchiveFromFile(file : NSString) -> SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks") {
do {
let sceneData = try NSData(contentsOfFile: path, options: NSDataReadingOptions.DataReadingMappedIfSafe)
let archiver = NSKeyedUnarchiver(forReadingWithData:sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! SKNode
archiver.finishDecoding()
return scene
} catch {
print("Error")
}
} else {
return nil
}
}
}