• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSKeyedArchiver - Writing to Existing File
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Font Manager changeFont Method
  • Next by Date: Re: -mouseMoved: not being called
  • Previous by thread: Re: Font Manager changeFont Method
  • Next by thread: Looking for a way to set alpha value of Desktop icons
  • Index(es):
    • Date
    • Thread