iOS 已弃用的 dataWithContentsOfMappedFile 替换

标签 ios swift cocoa-touch nsdata

这行代码:

let pkcs12Data = NSData.dataWithContentsOfMappedFile(path!)

在 XCode 7 中显示警告:

'dataWithContentsOfMappedFile' was deprecated in iOS 8.0: Use +dataWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead.

但是当我尝试任何建议时,我找不到任何响应建议的方法。有什么想法吗?

谢谢...

最佳答案

应该用作 init 方法:

let pkcs12Data = NSData(contentsOfURL: url, options: options, error: &error)

如果您使用的是 swift 2.x,您应该用 try 语句 包装。

关于iOS 已弃用的 dataWithContentsOfMappedFile 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32870855/

相关文章:

objective-c - MKStoreKit 自动更新订阅

ios - 保存按钮点击结果在 "unrecognized selector sent to instance"

swift - 在显示暂停计时器 Int 的标签上显示暂停和恢复的计时器

ios - 为什么 heightForRowAtIndexPath : come before cellForRowAtIndexPath:?

ios - 如何设置要放入 tableView 单元格中的 UIImage 的大小

ios - 在 IB 中的 GLKViewController 中的 Xcode 5 中,顶部/底部布局指南的用途是什么?

swift - Swift OSX 新增功能 : NSImageView Drawing multiple images with drawInRect - Can't update image

iOS Swift 新用户在应用程序终止并启动之前无法登录

ios - 使用 CAAnimationGroup 序列化动画

ios - 在 UITabBarController 中隐藏了 UINavigationController