Use NSString to load the file and put it in a text view:
NSTextView *textView; //your NSTextView object NSError *err = nil; NSString *path = [[NSBundle mainBundle] pathForResource:@"EditableFile" ofType:@"txt"]; NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err]; if(!contents) { //handle error } [textView setString:contents];
Conservation is just the opposite. Get the string and write it to a file:
NSTextView *textView; //your NSTextView object NSError *err = nil; NSString *path = [[NSBundle mainBundle] pathForResource:@"EditableFile" ofType:@"txt"]; NSString *contents = [textView string]; if(![contents writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&err]) { //handle error }
source share