NSKeyedArchiver - Writing to Existing File
NSKeyedArchiver - Writing to Existing File
- Subject: NSKeyedArchiver - Writing to Existing File
- From: haym37 <email@hidden>
- Date: Sun, 20 May 2007 18:27:34 -0400
Hi,
My program correspondings to an encoded file encoded via an
NSKeyedArchiver. Suppose I wanted to update a key/value pair in this
file. Take a look at the below method which performs this.
- (void)updateFileForKey:(NSString *)key andValue:(NSString *)value
{
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]
initForWritingWithMutableData:data];
NSString *fileName = [@"~/Desktop/myfile.txt"
stringByExpandingTildeInPath];
[archiver encodeObject:value forKey:key];
[archiver finishEncoding];
[data writeToFile:fileName atomically:YES];
[archiver release];
}
Clearly, however, the file now only contains one single key/value
pair. I do not want to reload the file, so how can I update the file
(in constant time) and change a key/value pair, without touching any
other keys/values?
Any help would be greatly appreciated. Thanks!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden