PDA

View Full Version : Problems saving data




mads379
Jun 1, 2009, 04:05 PM
Hello coders,
I'm having problems saving the data of my application so i can restore next time it launches.

I'm interested in saving an NSMutableArray which contains instances of my custom class FeedGroup

FeedGroup contains and NSMutableArray with instances of Feed and some ivars (NSMutableDictionary, and NSMutableAttributedString)

Instances of Feed contains a few ivars (3 x NSMutableArray, 1x NSMutableDictionary and 1x NSmutableAttributedString).

Both Feed and FeedGroup implement the NSCoding protocol.

I've tried saving the array that contains instances of FeedGroup by sending it the method
writeToFile: atomically

I've also using an NSKeyedArchiver like this:
[NSKeyedArchiver archiveRootObject:feedGroups toFile:@"feedGroup.plist"];

my last approch seems to save a file (the first didn't) but when i try to restore the data with:
feedGroups = [NSKeyedUnarchiver unarchiveObjectWithFile:@"feedGroup.plist"];

But it doesn't restore my data properly (my NSOutlineView doesn't show the data when i relaunch).

I archive the file in another file than the one i try to restore it (not sure if this maeks a difference).

Any help would be really appreciated,
Mads Hartmann Jensen



kainjow
Jun 1, 2009, 11:20 PM
"feedGroup.plist" is a relative path and you need to be using absolute paths, such as "/Users/me/Library/Application Support/MyApp/feedGroup.plist"

You can use NSSearchPathForDirectoriesInDomains() to find common folders.

mads379
Jun 2, 2009, 08:22 AM
Thank you kainjow, I've got it working now :)

I also found out that i wasn't retaining the values when i decoded them, which also gave a few bugs :)