SWIFT 代码 dataWithContentsOfFile 因更新到 XCode 6.1 而损坏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26605425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SWIFT code dataWithContentsOfFile broken with update to XCode 6.1
提问by Frankeex
Ever since the latest update to XCode the following two lines of codes have compile errors. Can anybody please advice me on the adjustments I need to make to get the program to compile and run again?
自从 XCode 的最新更新后,以下两行代码出现编译错误。任何人都可以请我建议我需要进行哪些调整才能使程序重新编译和运行?
var sceneData = NSData.dataWithContentsOfFile(path, options: .DataReadingMappedIfSafe, error: nil)
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData) archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
Any help would be appreciated, thank you.
任何帮助将不胜感激,谢谢。
回答by Duyen-Hoa
You can use (iOS < 8.0)
您可以使用 (iOS < 8.0)
NSData.dataWithContentsOfMappedFile(path)
or (iOS >= 7.0)
或(iOS >= 7.0)
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)
If you create a new SpriteKit sample project in XCode 6.1, you will see the changes.
如果您在 XCode 6.1 中创建一个新的 SpriteKit 示例项目,您将看到更改。
回答by CHUY THONG
try this
尝试这个
var sceneData = NSData(contentsOfFile: path!, options: .DataReadingMappedIfSafe, error: nil)