Re: coding NSNumber in NSArray?
Re: coding NSNumber in NSArray?
- Subject: Re: coding NSNumber in NSArray?
- From: Quincey Morris <email@hidden>
- Date: Mon, 14 Sep 2009 12:42:48 -0700
On Sep 14, 2009, at 12:10, Jon wrote:
maybe you ought to look and see if you can see where those words are
used, and how they are used...
Well, sorry, wasn't trying to cause offense.
BookMarkNode *node1 = [[BookMarkNode alloc] init];
[node1 setTypeOfLeaf:[NSNumber numberWithInt:0]];
You create a NSNumber here, which you pass to a method that *might* be
a setter (we don't know, because we don't get to see that code) and
therefore *might* put the NSNumber object into an instance variable
(again, we don't know).
[node1 setNodeTitle:@"eBay"];
[node1 setURL:@"http://www.ebay.com/"];
........etc.......
NSArray *allItems = [NSArray arrayWithObjects: node1, ..etc....
nil];
You create a NSArray here, apparently as a local variable that's never
used again. The *only* object you show putting in the array is a
BookMarkNode. This can't be your real code, because "..etc.... nil"
won't compile. So you *might* have simply abbreviated your real code,
or maybe you posted simplified code (people do that, often).
[node1 release];
//
-------------------------------------------------------------------------------
- (NSArray*)mutableKeys
{
NSArray *tempKeys = [NSArray arrayWithObjects:
@"typeOfLeaf",
@"nodeTitle",
@"urlString",
nil];
return tempKeys;
}
//
-------------------------------------------------------------------------------
- (id)initWithCoder:(NSCoder*)coder
{
self = [self init];
NSEnumerator *keysToDecode = [[self mutableKeys] objectEnumerator];
NSString *key;
while (key = [keysToDecode nextObject])
[self setValue:[coder decodeObjectForKey:key] forKey:key];
return self;
}
//
-------------------------------------------------------------------------------
- (void)encodeWithCoder:(NSCoder*)coder
{
NSEnumerator *keysToCode = [[self mutableKeys] objectEnumerator];
NSString *key;
while (key = [keysToCode nextObject])
[coder encodeObject:[self valueForKey:key] forKey:key];
}
You *might* be getting a NSNumber object as the value for key
"typeOfLeaf" (we don't know, because we don't get to see the getter
declaration). If so, you're *not* getting it out of an array, you're
getting it via KVC ('valueForKey:').
So why is your question about "coding NSNumber in NSArray"? What does
a NSArray have to do with your implementation of the NSCoding protocol?
when i look in the debugger at "allItems", the NSNumber is not
well defined.
What does "not well defined" mean? Is there an error message? Is there
an object of the wrong class? Is the object pointer trashed?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden