ios - `save(to:for:completionHandler:)` 中的 `UIDocument` 崩溃

标签 ios swift uidocument

save(to:for:completionHandler:) 上运行 iOS 9 的所有 32 位设备/模拟器上我都会崩溃。

Xcode 8.2。基本 SDK 是 10.2。目标是 9.0。标准架构。 Swift 3。适用于开发和发布版本。 Sample project.

找不到是否已知,也没有任何相关问题。你能推荐任何解决方法吗?我应该要求 64 位架构吗?

最佳答案

解决方法是返回 NS 对象,Apple 工程师特别推荐 NSMutableData:

override func contents(forType typeName: String) throws -> Any {  
    guard let data = text.data(using: .utf8) else { ... }
    if #available(iOS 10, *) {
        return data
    } else {
        return NSMutableData(data: data)
    }
}

关于ios - `save(to:for:completionHandler:)` 中的 `UIDocument` 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41099801/

相关文章:

iphone - TouchUpInside 事件后无法将 UIButton 保持在选定状态

iphone - 如果用户点击屏幕键盘,我如何关闭键盘?

ios - "ProjectName-Swift.h"找不到文件 - 共享扩展

ios - 如何将解析日期对象转换为字符串?

iCloud 文件在删除后不断重新出现

swift - UIDocument 在应用程序崩溃/强制退出时恢复未保存的更改

ios - 离开 ViewController 时停止 AVCaptureSession

ios - Gamecenter init/authentication 使 SpriteKit 的 Sprite 移动滞后

swift - 如何使用 Parse 子类和 User 之间的关系 - Swift

ios - 在 UIDocument 应用程序中添加图像缩略图