PDA

View Full Version : Whuh?




ATG
Nov 13, 2006, 05:22 AM
I'm getting a very weird error here:

datasourceArray = [[NSArray alloc] initWithObjects:@"Some", @"Items", @"That", @"Go", @"In", @"The", @"Sourcelist"];

That line is giving a signal 11 (SIGSEGV). I know it's that line because I've put NSLogs around the line and only the first appeared and I've commented it out and I didn't get an error.

Even odder is that I've got exactly the same line in -initWithType:error: and it goes fine (this is in -init)

datasourceArray is an IV BTW.

Am I doing something incredibly stupid?



robbieduncan
Nov 13, 2006, 05:47 AM
Did you read the documentation (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSArray/initWithObjects)? It makes it very, very clear what you are doing wrong. As you are not passing a count NSArray has no way of knowing how many objects you are passing. So you have to pass an additional nil to terminate the list like this:


NSArray *myArray = [[NSArray alloc] initWithObjects:@"I",@"should",@"read",@"the",@"docs",nil];

ATG
Nov 13, 2006, 05:54 AM
Oops

*digs hole*

FireArse
Nov 13, 2006, 06:04 AM
What do you do for a living? You say you don't often write code for the mac...

robbieduncan
Nov 13, 2006, 06:38 AM
What do you do for a living? You say you don't often write code for the mac...

I am a professional programmer! I work for Citigroup in London developing internal applications for the middle office. We mostly use SQL (Sybase flavour) with shell scripts, Perl, Java and a very tiny amount of C++. I write Cocoa stuff at home when I have spare time.