PDA

View Full Version : no readFromFile?!?!




liptonlover
Jul 6, 2008, 06:32 PM
Didn't expect to be posting again so soon, but here I am.

I'm trying to save and load from a text file. I set up a text file in my documents folder and can save to it,

#import "save.h"

@implementation save
NSString *path=@"/Users/nate/Documents/test.txt";
NSString *data;
- (IBAction)load:(id)sender {

}

- (IBAction)save:(id)sender {
data=[field stringValue];
[data writeToFile:path atomically:NO];
}
@end

(The text is definitely saving; I checked with textedit)

but I can't find any way to load. I'm looking under NSData but there is no readFromFile:Atomically: or anything like that.



Cromulent
Jul 6, 2008, 06:56 PM
This page explains it all.

http://developer.apple.com/documentation/Cocoa/Conceptual/AppFileMgmt/Tasks/WorkingWithFileWrappers.html#//apple_ref/doc/uid/20000775

Specifically:

Besides saving its contents to disk, a file wrapper can re-read them from disk when necessary. The needsToBeUpdatedFromPath: method determines whether a disk representation may have changed, based on the file attributes stored the last time the file was read or written. If the file wrapper’s modification time or access permissions are different from those of the file on disk, this method returns YES. You can then use updateFromPath: to re-read the file from disk.

liptonlover
Jul 6, 2008, 06:59 PM
Thanks! You're so darn helpful :)