Whuh?

Discussion in 'Mac Programming' started by ATG, Nov 13, 2006.

  1. ATG macrumors regular

    Joined:
    Aug 7, 2005
    #1
    I'm getting a very weird error here:

    Code:
    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?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Did you read the documentation? 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:

    Code:
    NSArray *myArray = [[NSArray alloc] initWithObjects:@"I",@"should",@"read",@"the",@"docs",nil];
    
     
  3. ATG thread starter macrumors regular

    Joined:
    Aug 7, 2005
  4. FireArse macrumors 6502a

    Joined:
    Oct 29, 2004
    #4
    robbieDuncan...

    What do you do for a living? You say you don't often write code for the mac...
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    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.
     

Share This Page