Reading Archived Data From File
Reading Archived Data From File
- Subject: Reading Archived Data From File
- From: "Frederick C. Lee" <email@hidden>
- Date: Tue, 8 Jun 2004 16:02:46 -0700
Greetings:
Scenario: My NSMutableDictionary is composed of {CountryName Key/
CountryModel objects}. The CountryModel is a custom class that
contains assorted instance variables including a NSMutableDictionary of
CityModels.
I'm trying to read/write theCountryMDict (NSMutableDictionary of
countries) to/from disk.
--------------------------------
1) Writing 'theCountryMDict ' appears to work (saved 242+ countries):
#pragma mark WRITING TO DISK
- (IBAction)saveDataToDisk:(id)sender {
if (![NSKeyedArchiver archiveRootObject:theCountryMDict
toFile:countryDataSource]) { // Good
NSLog(@"{saveDataToDisk} Sorry, the archiving failed.");
}
}
2) However, Reading the same archived data from disk fails:
//
------------------------------------------------------------------------
---------
#pragma mark READING FROM DISK
- (IBAction)readDataFromDisk:(id)sender {
theCountryMDict = [[NSUnarchiver
unarchiveObjectWithFile:countryDataSource] retain]; // Fails to
populate theCountryMDict.
}
========================================================================
===========
3) I get the following error:
*** +[NSUnarchiver unarchiveObjectWith
Data:]: extra data discarded
4) I did a [theCountryMDict count] and got zero (0):
ricCountries[915] {testAction} theCountryMDict count= 0
=================
5) Question: How can I successfully restore 'theCountryMDict' from
disk? What's wrong with using NSUnarchiver via #2) above?
Thanks in advance!
Regards,
Ric.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.