Search code examples
iosswiftuidocument

`save(to:for:completionHandler:)` of `UIDocument` crashes


I get crash on every 32 bit device / simulator running iOS 9 on save(to:for:completionHandler:).

Xcode 8.2. Base SDK is 10.2. Target is 9.0. Standard architectures. Swift 3. For both develop and release builds. Sample project.

Could not find if it's known, neither any related issues. Can you recommend any workaround? Should I require 64 bit architecture?


Solution

  • The work around is to return NS object, Apple engineer recommended NSMutableData specifically:

    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)
        }
    }