saving an object reference

  • I'm trying to work out how to save an object which references another
    type of object. Basically, I have one object, objectA, which uses a
    subclass of itself, objectB, to get information about its position on
    the page. So objectA always holds a reference to a given  objectB
    instance, and figures out its position based on that instance. This is
    a recent addition, and it seems to have broken saving and undo in my
    app, which is basically because I've no idea how to save an object
    reference...
    The system used for saving is just to put all of the 'vital
    statistics' of my objectA (and objectB, as well, since it's just a
    subclass) into an NSMutableDictionary, then write the dict to disk.
    Reading then just reads/parses the dict and re-builds the original
    objectA.

    But how do I store a reference (pointer) to an existing object in a
    dictionary?

    J.
  • I would suggest you read up on NSCoder. It provides a more
    sophisticated environment than archiving a dictionary.

    Mike.

    On 27 Dec 2007, at 18:28, James Maxwell wrote:

    > I'm trying to work out how to save an object which references
    > another type of object. Basically, I have one object, objectA, which
    > uses a subclass of itself, objectB, to get information about its
    > position on the page. So objectA always holds a reference to a
    > given  objectB instance, and figures out its position based on that
    > instance. This is a recent addition, and it seems to have broken
    > saving and undo in my app, which is basically because I've no idea
    > how to save an object reference...
    > The system used for saving is just to put all of the 'vital
    > statistics' of my objectA (and objectB, as well, since it's just a
    > subclass) into an NSMutableDictionary, then write the dict to disk.
    > Reading then just reads/parses the dict and re-builds the original
    > objectA.
    >
    > But how do I store a reference (pointer) to an existing object in a
    > dictionary?
    >
    > J.
  • > But how do I store a reference (pointer) to an existing object in a
    > dictionary?

      I'm not exactly sure I understand your goal, but storing (archiving/
    serializing) an object graph is traditionally done via the NSCoding
    Protocol:

    http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protoco
    ls/NSCoding_Protocol/Reference/Reference.html


    --
    I.S.
  • Okay, that's been the suggestion twice now... I've just started
    learning cocoa/obj-C, from java (I'm porting over some existing java
    code), so I started this project using a closely-related bit of sample
    code (Apple's Sketch app), and it seems to use an archived dictionary
    to save documents (but maybe I've just misunderstood the code!). I've
    just been trying to adapt that to suit my needs, but it looks like
    I've hit a wall with that plan! ;-)

    Thanks,

    J.

    On 27-Dec-07, at 10:44 AM, I. Savant wrote:

    >> But how do I store a reference (pointer) to an existing object in a
    >> dictionary?
    >
    > I'm not exactly sure I understand your goal, but storing (archiving/
    > serializing) an object graph is traditionally done via the NSCoding
    > Protocol:
    >
    > http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protoco
    ls/NSCoding_Protocol/Reference/Reference.html

    >
    > --
    > I.S.
    >
    >
    >
  • Le 27 déc. 07 à 20:27, James Maxwell a écrit :

    > Okay, that's been the suggestion twice now... I've just started
    > learning cocoa/obj-C, from java (I'm porting over some existing java
    > code), so I started this project using a closely-related bit of
    > sample code (Apple's Sketch app), and it seems to use an archived
    > dictionary to save documents (but maybe I've just misunderstood the
    > code!). I've just been trying to adapt that to suit my needs, but it
    > looks like I've hit a wall with that plan! ;-)
    >
    > Thanks,
    >
    > J.

    You can read The Serialization/Archving guide (http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Archivi
    ng.html

    )
    In the first chapter (Objects Graphs), there is a good explanation of
    the differences between writing a dictionary (Serialization) and
    saving an object graph (Archiving).
  • Cool. Serialization is, of course, what I'm used to in Java, but it's
    pretty much a no-brainer there. I'll read up on the Cocoa equivalents
    and see if I can wrap my head around it.

    cheers,

    J.

    On 27-Dec-07, at 11:38 AM, Jean-Daniel Dupas wrote:

    >
    > Le 27 déc. 07 à 20:27, James Maxwell a écrit :
    >
    >> Okay, that's been the suggestion twice now... I've just started
    >> learning cocoa/obj-C, from java (I'm porting over some existing
    >> java code), so I started this project using a closely-related bit
    >> of sample code (Apple's Sketch app), and it seems to use an
    >> archived dictionary to save documents (but maybe I've just
    >> misunderstood the code!). I've just been trying to adapt that to
    >> suit my needs, but it looks like I've hit a wall with that plan! ;-)
    >>
    >> Thanks,
    >>
    >> J.
    >
    > You can read The Serialization/Archving guide (http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Archivi
    ng.html

    > )
    > In the first chapter (Objects Graphs), there is a good explanation
    > of the differences between writing a dictionary (Serialization) and
    > saving an object graph (Archiving).
    >
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today