Subclassing UIDocument

In the sample app, each note that a user creates is an instance of a custom UIDocument subclass called ICFMyNoteDocument. Subclasses of UIDocument should implement the contentsForType:error: method and the loadFromContents:ofType:error: method, and then implement change tracking to enable UIDocument’s autosaving feature. Because the notes in the sample app are only storing the note text in a string, these methods are simple to implement.

- (id)contentsForType:(NSString *)typeName               error:(NSError *__autoreleasing *)outError{    if (!self.myNoteText)    {        [selfsetMyNoteText:@""];    }    NSData *myNoteData =    [self.myNoteText dataUsingEncoding:NSUTF8StringEncoding];     ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.