• 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: Combo Box Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Combo Box Problem (From: Ted Lowery <email@hidden>)

  • Prev by Date: Combo Box Problem
  • Next by Date: superclass and awakeFromNib
  • Previous by thread: Combo Box Problem
  • Next by thread: NSOutlineView crash?
  • Index(es):
    • Date
    • Thread