Re: Combo Box Problem
Re: Combo Box Problem
- Subject: Re: Combo Box Problem
- From: Christian Brunschen <email@hidden>
- Date: Sat, 30 Nov 2002 15:46:43 +0000
On Saturday, Nov 30, 2002, at 15:32 Europe/London, Ted Lowery wrote:
Any idea why this might intermittently fail?
- (void)windowDidLoad
{
[ownerField addItemsWithObjectValues:[NSArray
arrayWithObjects:@"Ted", @"Shannon"]];
You do know that [NSArray arrayWithObjects:...] requires one last
argument of 'nil' to signify the end of the list of objects with which
to initialize the array? Like so:
[NSArray arrayWithObjects:@"Ted", @"Shannon", nil]
Here's what NSArray's ocumentation says:
<quote>
+ (id)arrayWithObjects:(id)firstObj, ...
Creates and returns an array containing the objects in the argument
list. The argument list is a comma-separated list of objects ending
with nil.
</quote>
here's a stack trace:
0 CFRetain
1 CFArrayCreate
2 +[NSArray arrayWithObjects:count:]
3 +[NSArray arrayWithObjects:]
4 -[ActivityWindowController windowDidLoad]
Basically, the code that creates the array will walk through the
argument list (on the stack) until it finds a *nil*. If you don't give
it one, it will walk further through the stack, over values that are
not pointers to objects at all, and this is the likely cause for the
problem. Occasionally, though, there _happens_ to be a byte pattern
that matches a *nil* pointer, and those are the cases when your code
does work - by accident :)
...
Cheers, Ted
Best wishes,
// Christian Brunschen
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.