• 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: Create NSArray from persistent storage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Create NSArray from persistent storage (From: Ivan Myrvold <email@hidden>)

  • Prev by Date: Visualizing Cocoa
  • Next by Date: Re: Visualizing Cocoa
  • Previous by thread: Re: Create NSArray from persistent storage
  • Next by thread: how to highlight a non-editable NSTextView selection
  • Index(es):
    • Date
    • Thread