Keyed Archiving.

  • I'm creating a program that is project based similar in ways to XCode.
    Thus when a new project is created I need to automatically have the
    application create the default project document.
    For this, once I have the path I use: [NSArchiver
    archiveRootObject:newDoc toFile:[NSString stringWithFormat:@"%@/
    %@.arcproj",destination,[destination lastPathComponent]]];
    I assumed this would automatically archive the default document.
    however, when I attempt to create a new project I get this error message:***
      -encodeObject:forKey: only defined for abstract class.  Define -
    [NSArchiver encodeObject:forKey:]!

    Which I simply do not understand.  The error does not make sense to me.

    The NSDocument subclass has the following encodeWithCoder override:
    -(void)encodeWithCoder:(NSCoder*)coder
    {
    NSLog(@"CAlling encode with coder %@",coder);
    //It fails here before encoding or writing anything to disk. the
    above NSLog prints but nothing else happens.
    [coder encodeObject:projectDict forKey:@"ProjectDict"];
    [coder encodeObject:projectStruct forKey:@"ProjectStruct"];
    [coder encodeObject:_root forKey:@"ROOT"];
    NSLog(@"Reached end of encode");
    }
  • Howdy,

    Maybe you're looking for [NSKeyedArchiver archiveRootObject:toFile:]
    instead?

    http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Tasks/c
    reating.html


    - Tony

    On Dec 4, 2007, at 1:15 PM, Development wrote:

    > I'm creating a program that is project based similar in ways to
    > XCode. Thus when a new project is created I need to automatically
    > have the application create the default project document.
    > For this, once I have the path I use: [NSArchiver
    > archiveRootObject:newDoc toFile:[NSString stringWithFormat:@"%@/
    > %@.arcproj",destination,[destination lastPathComponent]]];
    > I assumed this would automatically archive the default document.
    > however, when I attempt to create a new project I get this error message:***
    > -encodeObject:forKey: only defined for abstract class.  Define -
    > [NSArchiver encodeObject:forKey:]!
    >
    > Which I simply do not understand.  The error does not make sense to
    > me.
    >
    > The NSDocument subclass has the following encodeWithCoder override:
    > -(void)encodeWithCoder:(NSCoder*)coder
    > {
    > NSLog(@"CAlling encode with coder %@",coder);
    > //It fails here before encoding or writing anything to disk. the
    > above NSLog prints but nothing else happens.
    > [coder encodeObject:projectDict forKey:@"ProjectDict"];
    > [coder encodeObject:projectStruct forKey:@"ProjectStruct"];
    > [coder encodeObject:_root forKey:@"ROOT"];
    > NSLog(@"Reached end of encode");
    > }
  • I'm still getting the same error. It only happsn when I try to use
    keyvalue encoding which of course is important.

    On Dec 4, 2007, at 2:47 PM, Tony Parker wrote:

    > Howdy,
    >
    > Maybe you're looking for [NSKeyedArchiver archiveRootObject:toFile:]
    > instead?
    >
    > http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Tasks/c
    reating.html

    >
    > - Tony
    >
    > On Dec 4, 2007, at 1:15 PM, Development wrote:
    >
    >> I'm creating a program that is project based similar in ways to
    >> XCode. Thus when a new project is created I need to automatically
    >> have the application create the default project document.
    >> For this, once I have the path I use: [NSArchiver
    >> archiveRootObject:newDoc toFile:[NSString stringWithFormat:@"%@/
    >> %@.arcproj",destination,[destination lastPathComponent]]];
    >> I assumed this would automatically archive the default document.
    >> however, when I attempt to create a new project I get this error message:***
    >> -encodeObject:forKey: only defined for abstract class.  Define -
    >> [NSArchiver encodeObject:forKey:]!
    >>
    >> Which I simply do not understand.  The error does not make sense to
    >> me.
    >>
    >> The NSDocument subclass has the following encodeWithCoder override:
    >> -(void)encodeWithCoder:(NSCoder*)coder
    >> {
    >> NSLog(@"CAlling encode with coder %@",coder);
    >> //It fails here before encoding or writing anything to disk. the
    >> above NSLog prints but nothing else happens.
    >> [coder encodeObject:projectDict forKey:@"ProjectDict"];
    >> [coder encodeObject:projectStruct forKey:@"ProjectStruct"];
    >> [coder encodeObject:_root forKey:@"ROOT"];
    >> NSLog(@"Reached end of encode");
    >> }
    >
  • Jeez I'm sorry I miss read what you sent. I'm sorry your right I was
    not envoking the keyed archiving.

    On Dec 4, 2007, at 2:54 PM, Development wrote:

    > I'm still getting the same error. It only happsn when I try to use
    > keyvalue encoding which of course is important.
    >
    > On Dec 4, 2007, at 2:47 PM, Tony Parker wrote:
    >
    >> Howdy,
    >>
    >> Maybe you're looking for [NSKeyedArchiver
    >> archiveRootObject:toFile:] instead?
    >>
    >> http://developer.apple.com/documentation/Cocoa/Conceptual/Archiving/Tasks/c
    reating.html

    >>
    >> - Tony
    >>
    >> On Dec 4, 2007, at 1:15 PM, Development wrote:
    >>
    >>> I'm creating a program that is project based similar in ways to
    >>> XCode. Thus when a new project is created I need to automatically
    >>> have the application create the default project document.
    >>> For this, once I have the path I use: [NSArchiver
    >>> archiveRootObject:newDoc toFile:[NSString stringWithFormat:@"%@/
    >>> %@.arcproj",destination,[destination lastPathComponent]]];
    >>> I assumed this would automatically archive the default document.
    >>> however, when I attempt to create a new project I get this error message:***
    >>> -encodeObject:forKey: only defined for abstract class.  Define -
    >>> [NSArchiver encodeObject:forKey:]!
    >>>
    >>> Which I simply do not understand.  The error does not make sense
    >>> to me.
    >>>
    >>> The NSDocument subclass has the following encodeWithCoder override:
    >>> -(void)encodeWithCoder:(NSCoder*)coder
    >>> {
    >>> NSLog(@"CAlling encode with coder %@",coder);
    >>> //It fails here before encoding or writing anything to disk. the
    >>> above NSLog prints but nothing else happens.
    >>> [coder encodeObject:projectDict forKey:@"ProjectDict"];
    >>> [coder encodeObject:projectStruct forKey:@"ProjectStruct"];
    >>> [coder encodeObject:_root forKey:@"ROOT"];
    >>> NSLog(@"Reached end of encode");
    >>> }
    >>

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