• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problem with NSUnarchiver
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with NSUnarchiver


  • Subject: Re: problem with NSUnarchiver
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 7 Mar 2005 09:38:36 -0800


On Mar 6, 2005, at 4:19 PM, simone gabbriellini wrote:

(1) loadData = [[NSMutableArray alloc]initWithCapacity:4];
(2) loadData = [NSUnarchiver unarchiveObjectWithData:newData];
and I have:
(3) loadData = [[coder decodeObject] retain];
in my initWithCoder function
the fact is that if I ask to print the array at point (1) I obviusly obtain this ()
if I ask to printf the array at step (3) I got (ciao, come, stai, "adesso?") - which is the content previusly saved, but when I finally came to step (2) printf give me this result:
<MyDocument: 0x3b9090>
where is the content of my array? at this point, I'm not able to retrive it...

The array is in an instance variable of the document instance...

In your archiving method:

On Mar 3, 2005, at 10:46 AM, simone gabbriellini wrote:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
    // saving data
    if([aType isEqualToString:@"invitiEase"]){
        return [NSArchiver archivedDataWithRootObject:self];
    }
    return nil;
}

you archived the document, not the array. The method should have been more like:

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
    // saving data
    if([aType isEqualToString:@"invitiEase"]){
        return [NSArchiver archivedDataWithRootObject:arrayInvito];
    }
    return nil;
}


That said, the approach you're taking to archiving in general is, to say the least, peculiar. Your document class should not be implementing NSCoding. The document typically manages either a root model object or a collection of objects that are added to an archive in dataRepresentationOfType: and extracted in loadDataRepresentation:ofType:.



Given the other questions you are asking here, I would recommend that you get hold of one of the introductory Cocoa texts and work through that. Learning piecemeal by trial and error is unlikely to be the most productive or rewarding experience.


mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >problem with NSUnarchiver (From: simone gabbriellini <email@hidden>)

  • Prev by Date: Re: Weird image size
  • Next by Date: [Moderator] Cocoa and list resources
  • Previous by thread: problem with NSUnarchiver
  • Next by thread: Quick polymorphism and subclassing question
  • Index(es):
    • Date
    • Thread