Adding saving to a Document based app

Discussion in 'Mac Programming' started by zedLondon, Jun 25, 2007.

  1. macrumors member

    Joined:
    Jun 25, 2007
    Location:
    London
    #1
    Hey everyone

    I was hoping someone here could help me. I'm quite new to both Obj-c and Cocoa and have been trying to teach myself by building a few trivial apps. The latest is a searchable dictionary app, which allows users to add and remove entries. (I want to use it for conlangs)

    Anyway the app is a Cocoa document based app and has three classes.
    1. a MyDocument class which inherits from NSDocument
    2. a FilteredArrayController which inherits from NSArrayController. It reimplements the newObject: and adds a search functionailty by reimplementing arrangeObjects:
    3. a Word class which stores a word, it's meaning, etymology and notes.

    Now I thought that in order to add saving to the app I had to implement a few methods in the MyDocument class and have custom classes to archive themselves.

    So in MyDocument I added this:
    Where words is an NSMuatableArray. The class also has an IBOutlet to an NSArrayController which is linked to my custom NSArrayController. All the UI elements are bound to this ArrayController.

    In my Word class I've added the following:

    From what I undertsand this should have worked. The app seems to save fine, but When i load up a file the UI elements are not populated. Is this because I need to manually repopulate the ArrayController or is there something really simple I'm missing here.?
     
  2. macrumors member

    Joined:
    Oct 19, 2006
    Location:
    Atlanta, GA
    #2
    Does your Word clas implement the NSCoding protocol?
     
  3. thread starter macrumors member

    Joined:
    Jun 25, 2007
    Location:
    London
    #3
    Yes it does

    If i understand it correctly all I need to do is this:

    to implement NSCoding right?
     
  4. thread starter macrumors member

    Joined:
    Jun 25, 2007
    Location:
    London
    #4
    sussed it

    I deserve a great big thwak over the head. I forgot to set the content array binding of my array controller. So when my document attempted to archive my words array, it was empty as the array controller hadn't been passing the info back to it.

    *slaps forehead* :)
     

Share This Page