hiddenpremise
Feb 17, 2009, 08:25 PM
For the life of me I can't figure out how to archive and unarchive the content of an NSTextView. I want to be able to put some text into it, save it to a file, and have that text pop up when I start the app back up again. I do not want to use bindings at all, as my more specific purpose makes using them impossible.
My current attempts something like this
NSData *dataToWrite = [NSKeyedArchiver archivedDataWithRootObject: [theTextView textContainer]];
[dataToWrite writeToFile:[@"~/Documents/test.test" stringByExpandingTildeInPath] atomically:YES];
Then I put something in the awakeFromNib like this
NSTextContainer *tempText = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:[@"~/Documents/test.test" stringByExpandingTildeInPath]]];
[theTextView replaceTextContainer: tempText];
So far this has not worked. It saves. You can go to the file, open it with plist editor, and verify that you have saved a NSTextContainer. I just can't load it back into the blashed textView.
My current attempts something like this
NSData *dataToWrite = [NSKeyedArchiver archivedDataWithRootObject: [theTextView textContainer]];
[dataToWrite writeToFile:[@"~/Documents/test.test" stringByExpandingTildeInPath] atomically:YES];
Then I put something in the awakeFromNib like this
NSTextContainer *tempText = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:[@"~/Documents/test.test" stringByExpandingTildeInPath]]];
[theTextView replaceTextContainer: tempText];
So far this has not worked. It saves. You can go to the file, open it with plist editor, and verify that you have saved a NSTextContainer. I just can't load it back into the blashed textView.
