NSArray may not respond to '-length'

Discussion in 'iPhone/iPad Programming' started by Macman1993, Feb 23, 2011.

  1. macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #1
    Not exactly what I am doing wrong here but I create an array of dictionaries from a .plist file and it appears to all work perfectly. I can access the files in it without any issues but when I try to call [array length] I get two warnings.

    'NSArray' may not respond to '-length'
    'Comparison between pointer and integer'

    I cant tell what I am doing wrong here as I have called length a million times before. I am calling 'length' in a for loop, plugging the exact number by hand works but it will not always work since I can't know the size of the array in advance. Heres my code for initializing the array and the start of the for loop. Can someone please explain what I got wrong?

    Code:
    NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString: @"http://web.suffieldacademy.org/~12clm/data.plist"]];
    	
    	
    	NSArray *people = [dictionary valueForKey:@"People"];
    
    	AppDelegate_Shared  *appDelegate =
    	[[UIApplication sharedApplication] delegate];
    	NSManagedObjectContext *context = [appDelegate managedObjectContext];
    	NSError *error;
    
    	//ISSUE HAPPENS HERE!!!!
    	for (int i = 0;i<[people length]; i++) {
    
    
    
    I have used breakpoints / other debug code and can verify that the line in question is what is causing the problem. When this line is run I get "SIGABRT" any help would be greatly appreciated.
     
  2. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    It's not length. It's count. Make sure you read the sdk documentation, it would have quickly answered this.
     
  3. thread starter macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #3
    ...woops, sorry I have spent to much time on Java recently, when I looked through the documentation I read count but it never occurred to me that I mixed the two up.
     

Share This Page