Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-04-2008, 03:18 PM   #6 (permalink)
myersn024
Tutorial Author
 
Join Date: May 2008
Posts: 315
myersn024 is an unknown quantity at this point
Default

I use NSKeyedArchivers and NSKeyedUnarchivers for all of my saving needs at the moment, and I see one difference between what you're doing and what I'm doing. I know that you can just call encodeObject, but I've never had much luck with that. You might try something like this.
Code:
- (void) encodeWithCoder: (NSCoder *) encoder {
	[encoder encodeObject: self.traditional forKey:@"traditional"];
	[encoder encodeObject: self.simplified forKey:@"simplified"];
	[encoder encodeObject: self.pinyin forKey:@"pinyin"];
	[encoder encodeObject: self.english forKey:@"english"];
}

- (id) initWithCoder: (NSCoder *) decoder {
	self.traditional = [[decoder decodeObjectForKey:@"traditional"] retain];
	self.simplified = [[decoder decodeObjectForKey:@"simplified"] retain];
	self.pinyin = [[decoder decodeObjectForKey:@"pinyin"] retain];
	self.english = [[decoder decodeObjectForKey:@"english"] retain];
	
	return self;
}
You may have to change your code to save the data as well. Something like this in your applicationWillTerminate function should work. wordArray is the array that holds your dictionary info when it's read into memory.
Code:
NSMutableData *theData = [NSMutableData data];
NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData];

[encoder encodeObject:wordArray forKey:@"wordArray"];
[encoder finishEncoding];
[theData writeToFile:yourFilePath atomically:YES];
[encoder release];
Then, you can read it back in your applicationDidFinishLaunching method like this.
Code:
NSData *theData = [NSData dataWithContentsOfFile:yourFilePath];
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
wordArray = [[decoder decodeObjectForKey:@"wordArray"] retain];
I did a tutorial over how to use NSKeyedArchivers and NSKeyedUnarchivers, which can be found in the tutorial section.
myersn024 is offline   Reply With Quote
 

» Advertisements
» Online Users: 714
19 members and 695 guests
7twenty7, alexeir, BuzzingDanZei, chiataytuday, daarshg, Fahad.bhutta, iAppDeveloper, iOS.Lover, jujuforce, MAMN84, MarkC, m_rozzi, QuantumDoja, raymng, sigluca, Sophie100, t14hoangson, teebee74, tim0504
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,474
Threads: 94,040
Posts: 402,626
Top Poster: BrianSlick (7,978)
Welcome to our newest member, m_rozzi
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.