Re: Create NSArray from persistent storage
Re: Create NSArray from persistent storage
- Subject: Re: Create NSArray from persistent storage
- From: Scott Anguish <email@hidden>
- Date: Mon, 18 Jun 2001 01:52:05 -0400
Actually, your array is exactly what you'd expect.. you're adding a
single NSData item to the array
- (void)restoreFromStorage:(NSData *)data {
NSArray *theArray;
theArray=[NSArray arrayWithObject:data];
NSLog(@"theArray size: %d", [theArray count]);
[self setDataArray:theArray];
}
What you want to do is either this (for your restoreFromStorage)
- (void)restoreFromStorage:(NSData *)data {
NSString *tempString;
NSArray *theArray;
tempString=[[NSString alloc] initWith
Data:data
encoding:NSUTF8StringEncoding];
theArray=[tempString propertyList];
[self setDataArray:theArray];
}
or, you could instead use the file handling method of dealing with Data
in the NSDocument classes
- (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)type
{
NSArray *theArray;
theArray=[NSArray arrayWithContentsOfFile:fileName];
[self setDataArray:theArray];
return (theArray !=nil);
}