Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created December 28, 2013 02:04
Show Gist options
  • Select an option

  • Save keicoder/8155229 to your computer and use it in GitHub Desktop.

Select an option

Save keicoder/8155229 to your computer and use it in GitHub Desktop.
objective-c : Subclassing UIDocument 심플 예제
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