• 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
encoding/decoding mutable array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

encoding/decoding mutable array


  • Subject: encoding/decoding mutable array
  • From: Ryan Glover <email@hidden>
  • Date: Thu, 22 Jun 2006 22:57:01 -0400

Hello,

I have a program with a mutable array of objects that I am trying to save using a NSKeyedArchiver. Each object in the array has a number of NSString properties that are saved properly (i.e. it works) via the encodeWithCoder method in the object class. However, each object also has it's own mutable array of a second type of object. I have implemented encodeWithCoder in the second class as I did in the first. Unfortunately, when I call encodeObject for the second mutable array, the encodeWithCoder method for the second class appears not to be called as the data is not saved. I have the format of the save as xml so I can view it's contents, and it doesn't contain the information for the objects in the second mutable array.

To summarize the flow.

MyDocument.m has the following where 'sources' is my top level mutable array.

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
[archiver encodeObject:sources forKey:@"sources"];
[archiver finishEncoding];
[archiver release];
return data;
}


Sources is an array of objects GenericSource.h which has the following method.

-(void)encodeWithCoder:(NSCoder *)coder
{
	[coder encodeObject:sourceName forKey:@"sourceName"];
	[coder encodeObject:genericEmission forKey:@"genericEmission"];
	// encode array of emissions
	[coder encodeObject:emissions forKey:@"emissions"];
}

Where the last object, emissions, is an array of objects of type Emission.h. Emission.m has the following method.

-(void)encodeWithCoder:(NSCoder *)coder
{
	[coder encodeObject:cas forKey:@"cas"];
	[coder encodeObject:emission forKey:@"emission"];
}

My question is, do I need to do something different when trying to encode an array object as opposed to a NSString?

Note that the code does not fail, it just doesn't save the emissions information. It saves the sourceName and genericEmission values fine and the decoding methods repopulate the UI just as I would expect (except for the emissions array).

Any input would be appreciated.

Thank you,
Ryan Glover



_______________________________________________
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


  • Follow-Ups:
    • Re: encoding/decoding mutable array
      • From: James Bucanek <email@hidden>
  • Prev by Date: How to hide an NSTableView
  • Next by Date: NSSearchField with bindings: how to get notifications
  • Previous by thread: Re: How to hide an NSTableView
  • Next by thread: Re: encoding/decoding mutable array
  • Index(es):
    • Date
    • Thread