Re: Reading Archived Data From File
Re: Reading Archived Data From File
- Subject: Re: Reading Archived Data From File
- From: "Mark A. Stratman" <email@hidden>
- Date: Tue, 8 Jun 2004 18:48:11 -0500
Does the dictionary contain any custom objects you've created? (It
sounds like it, but just to be sure...)
If so, you probably need to add some NSCoder methods to that class;
namely "initWithCoder:" and "encodeWithCoder:".
Have a look at
http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/
Tasks/codingobjects.html
HTH,
- Mark
On Jun 8, 2004, at 6:02 PM, Frederick C. Lee wrote:
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 unarchiveObjectWithData:]: 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.
_______________________________________________
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.