Saving and loading UIDocumentBrowserViewController

474 views Asked by At

I know I can encode/decode my files for saving/loading at my UIDocument from UIDocumentBrowserViewController using the code below, as explained on Apple's 2017 WWDC.

class Document: UIDocument
{
override func contents(forType typeName: String) throws -> Any
{
    return NSKeyedArchiver.archivedData(withRootObject: myRootObject)
}

override func load(fromContents contents: Any, ofType typeName: String?) throws
{
    guard let data = contents as? data else { return }
    guard let rootObject = NSKeyedUnarchiver.unarchiveObject(with: data) as? MyRootObject else { return }
    myRootObject = rootObject
}
}

However, the code above is ineficient for larger files (300MB+) and more complex object graphs, which is the case of my application.

I imagine that it would be necessary to implement some kind of incremental saving. However, I have no idea on how to achieve such and could not find any tutorials or documentation on the subject. Additionaly, NSKeyedArchiver seems to be a slow alternative, so should I use something else for the incremental saving? What would be a good/fast way to implement saving/loading?

0

There are 0 answers