Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mads379

macrumors newbie
Original poster
Jun 1, 2009
2
0
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:mad:"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:mad:"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

Moderator emeritus
Jun 15, 2000
7,958
7
"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

macrumors newbie
Original poster
Jun 1, 2009
2
0
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 :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.