Initting NSArray with NSString's -propertyList method
Initting NSArray with NSString's -propertyList method
- Subject: Initting NSArray with NSString's -propertyList method
- From: Greg Anderson <email@hidden>
- Date: Mon, 28 Jan 2002 17:14:28 -0600
In my document class, I'm saving my array data by using this code:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
if ([aType isEqualToString:ChartDocumentType]) {
NSString *string = [iColumns description];
return [string dataUsingEncoding:NSASCIIStringEncoding];
} else {
return nil;
}
}
On the other side, I load it with:
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
if ([aType isEqualToString:ChartDocumentType]) {
NSString *string = [[NSString allocWithZone:[self zone]]
initWith
Data:data encoding:NSASCIIStringEncoding];
iColumns = [[string propertyList] retain];
[iChartView setDataArray:iColumns];
[string release];
return YES;
} else {
return NO;
}
}
My problem's coming from the [string propertyList] method. It
always gives me the error:
2002-01-28 17:07:17.151 Charter[5806] Unexpected character ( at line 0
According to NSString's -propertyList description, it should be
able to figure out that a well-formed property list beginning with a '('
means that it's an NSArray. The file that's written out looks fine to
me, but I can't get it back into my code. My searches through the
archives showed this to be the expected way to save and retrieve NSArray
data to and fro a disk file.
Am I missing something obvious here (it must be obvious, elsewise
it wouldn't be so difficult to nail down)? The only slightly weird thing
about this array is that it's an array of dictionaries, but from the
errors I'm getting, it doesn't look like it's parsing anywhere past the
first character of the input file.
Thanks.
Greg