Re: Create NSArray from persistent storage
Re: Create NSArray from persistent storage
- Subject: Re: Create NSArray from persistent storage
- From: Gideon Tearle <email@hidden>
- Date: Mon, 18 Jun 2001 08:35:29 +0100
Hi Ivan
The strange thing here is that NSLog always says that I have an array
of size 1, even if I have several entries (here I showed two). What
should I do, to get the array correctly populated (with 1 NSDictionary
instance in each element?
Your code is creating a single element array *containing* the plist data
whereas what you're trying to do is create an array *from* the plist
data. So you'd be better off subclassing NSDocument's
readFromFile:ofType: and then use the passed filename for NSArray's
initWithContentsOfFile:
So:
- (BOOL)readFromFile:(NSString *)thePath ofType:(NSString *)aType
{
if ([aType isEqualToString:myDocumentType])
{
[self restoreFromFile:thePath];
return YES;
}
else
{
return NO;
}
}
- (void) restoreFromFile:(NSString *) thePath
{
NSArray *theArray;
theArray = [[NSArray alloc] initWithContentsOfFile: thePath];
NSLog(@"theArray size: %d", [theArray count]);
[self setDataArray:theArray];
[theArray release];
}
Best wishes
-- Gideon