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, 02:23 AM   #1 (permalink)
chuck
Registered Member
 
chuck's Avatar
 
Join Date: Aug 2008
Location: Berlin, Germany
Posts: 87
chuck is on a distinguished road
Default archiving an object? (NSKeyedArchiver, SQLite or CoreData)

I'm writing a dictionary application and the source of my dictionary is a txt file, but I need to either parse it into an array of DictEntry [custom] objects or put everything into a read-only database. Currently I take the dictionary from the file, split it by line and then parse each line, but while this works fine in Simulator, it is VERY slow in the iPhone (about 30 secs to load or so, unacceptable for a dictionary). The dictionary text file itself is 4.5 MB.

Now, I thought of serializing my DictEntries array to a file, but found that object serialization is deprecated in preference to object archiving with NSKeyedArchiver. Even though I have encodeWithCoder and initWithCoder functions in my DictEntry class, it still doesn't work. It says "Archiving SUCCESS" even though it doesn't seem to write anything:

Code:
dictEntries = [[NSMutableArray alloc] initWithCapacity:71080];
	
// -snip- Code to put stuff into array is here

NSString *arrayPath = (NSString*)[[NSBundle mainBundle] pathForResource:@"DictEntries" ofType:@"arch"];
if ( [NSKeyedArchiver archiveRootObject:dictEntries toFile:arrayPath] == NO ) {
  NSLog( @"Archiving FAIL!" );
} else {
  NSLog( @"Archiving SUCCESS!" );
}
I'm considering going with an SQLite database, but since everything works in an array of objects already, I don't really see the point. Is there some easy way to archive an array of custom user-defined objects to a file that I'm missing? I also tried [dictEntries writeToFile:arrayPath atomically:YES] but it returns fail.

Any more ideas? Perhaps the application bundle is read-only? I've already wasted a few good hours on this... Any help would be greatly appreciated.
chuck is offline   Reply With Quote
 

» Advertisements
» Online Users: 793
21 members and 772 guests
apatsufas, armmzz, chenpo, Domele, erikmcmullan, falco1973, headkaze, jarv, Kirkout, Lily.P, lzwasyc, mapiko, michelesasbury, mystic.purple, Paul Slocum, pbart, PtSy, samball, Sami Gh, walex, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,470
Threads: 94,037
Posts: 402,620
Top Poster: BrianSlick (7,978)
Welcome to our newest member, michelesasbury
Powered by vBadvanced CMPS v3.1.0

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