• 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: David P Henderson <email@hidden>
  • Date: Mon, 18 Jun 2001 01:26:06 -0400

On Monday, June 18, 2001, at 12:20 , Ivan Myrvold wrote:

- (void)restoreFromStorage:(NSData *)data {
NSArray *theArray;
theArray=[NSArray arrayWithObject:data];
NSLog(@"theArray size: %d", [theArray count]);
[self setDataArray:theArray];
}

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?

Actually, this isn't strange behavior at all. You are creating an array of one element; your data object. +arrayWithObject: is what you want here; you are thinking that +arrayWithObject: is doing +arrayFromData: but no such method exists. What you need to do is convert the data object representation of your property list into an array. Take a look at what Bill Cheeseman does in Vermont Recipes in this situation.

- (void)restoreFromStorage:(NSData *)data {
NSDictionary *dictionary = [self setupDictionaryFromStorage:data];
[[self mySettings] restoreFromDictionary:dictionary];
}

- (NSDictionary *)setupDictionaryFromStorage:(NSData *)data {
NSString *string = [[NSString allocWithZone:[self zone]] initWithData:data encoding: NSASCIIStringEncoding]; // Convert the data into an NSString instance
NSDictionary *dictionary = [string propertyList]; // Use the NSString -propertyList method to convert the string instance into the appropriate container
[string release];
return dictionary;
}

In your case substitue:
NSArray *theArray = [string propertyList];

Dave
--
Chaos Assembly Werks
"Nothing is too good to be true, except, perhaps, the morality of a bishop."
- Israel Zangwill


  • Follow-Ups:
    • Re: Create NSArray from persistent storage
      • From: Ivan Myrvold <email@hidden>
References: 
 >Create NSArray from persistent storage (From: Ivan Myrvold <email@hidden>)

  • Prev by Date: Create NSArray from persistent storage
  • Next by Date: Re: Create NSArray from persistent storage
  • Previous by thread: Create NSArray from persistent storage
  • Next by thread: Re: Create NSArray from persistent storage
  • Index(es):
    • Date
    • Thread