Help with Save/Load Cocoa App

Discussion in 'Mac Programming' started by stadidas, Nov 5, 2006.

  1. stadidas macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #1
    I have been developing a little Cocoa app recently to help me manage my money whilst at Uni. It's been coming along very nicely, and seems to works pretty much just as I'd like. It currently looks like this:
    [​IMG]

    I have added the ability to save the file through - (NSData *)dataRepresentationOfType: (NSString *)aType in MyDocument, but I'm not sure how to implement loading. I have uploaded the XCode project here if anyone would like to take a look at it and help me out. The example in the Hillegass is pretty different to my app and I can't work out how to add loading in my application. I'm sure one of you guys could figure it out though.
     
  2. stadidas thread starter macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #2
    OK I looked at a file I saved in Property List Editor and it's saving all the values as 0, so save isn't actually working at all. If someone with some Cocoa experience could please look at this I'd be very grateful.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    You have to tell your object controller what it's controlling. The values aren't getting saved because the bindings system isn't even setting the values of your variables in the first place. In this case, you want it to link to the detailsController in your document, so in IB, bind the "Controller Content" of objectController to File's Owner (your document), with the path as "detailsController".

    For loading it, just do something like this:
    Code:
    - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType {
    	detailsController = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        return YES;
    }
    It can get a little more complicated if you want to do a bunch of custom stuff, but I think that would work in this case.

    bindings.png
     
  4. stadidas thread starter macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #4
    Thank you so much! :) I'm very new to Cocoa and rushed through the Hillegass book a bit, that was a really stupid mistake to make.
    I'm putting a special thank you to you in the 'About' window... not that you probably care as I'm the only person who's likely to use the program.
    Thanks again though!
     

Share This Page