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.