Problems saving data

Discussion in 'Mac Programming' started by mads379, Jun 1, 2009.

  1. macrumors newbie

    Joined:
    Jun 1, 2009
    #1
    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
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    "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.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 1, 2009
    #3
    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 :)
     

Share This Page