Created
December 28, 2013 02:04
-
-
Save keicoder/8155229 to your computer and use it in GitHub Desktop.
objective-c : Subclassing UIDocument 심플 예제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Subclassing UIDocument 심플 예제 | |
| .h | |
| @property (strong) NSString * noteContent; | |
| .m | |
| //Two override points, one when read and one when write. | |
| //Called when the application reads data from the file system | |
| - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError | |
| { | |
| if ([contents length] > 0) { | |
| self.noteContent = [[NSString alloc] initWithBytes:[contents bytes] | |
| length:[contents length] | |
| encoding:NSUTF8StringEncoding]; | |
| } else { | |
| // When the note is created, assign default content | |
| self.noteContent = @"Empty"; | |
| } | |
| [[NSNotificationCenter defaultCenter] postNotificationName:@"noteModified" object:self]; | |
| return YES; | |
| } | |
| // Called when the application (auto)saves the content of a note | |
| - (id)contentsForType:(NSString *)typeName error:(NSError **)outError | |
| { | |
| if ([self.noteContent length] == 0) { | |
| self.noteContent = @"Empty"; | |
| } | |
| return [NSData dataWithBytes:[self.noteContent UTF8String] | |
| length:[self.noteContent length]]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment