views:

51

answers:

1

my attempt to init an array with a number of bool values using:

[myArray initWithObjects:[NSNumber numberWithBool:YES], 
                         [NSNumber numberWithBool:YES], 
                         [NSNumber numberWithBool:YES],
                         nil];

seems to fail since the debugger shows an empty array after this statement is carried out ... Any clues?

+3  A: 

Make sure you are alloc-ing the object, as well, i.e.:

NSArray *myArray = [[NSArray alloc] initWithObjects:...];
...
[myArray release];

Or:

NSArray *myArray = [[[NSArray alloc] initWithObjects:...] autorelease];

Or:

NSArray *myArray = [NSArray arrayWithObjects:...];
Alex Reynolds
or better use NSArray arrayWithObjects: to do both at once
Mark
Sometimes it is preferable to alloc-init, to be able to release the array as soon as it is no longer needed. But either way works.
Alex Reynolds
Thanks to all of you. I found the bug. I did an initWithContentsOfFile that, when unsuccessful, should load the defaults. The missing link was that I had to alloc/init in case the loading from file fails.
iFloh