NSArray may not respond to '-length'

Discussion in 'iOS Programming' started by Macman1993, Feb 23, 2011.

  1. Macman1993 macrumors 6502


    Nov 23, 2007
    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?

    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;
    	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. ulbador macrumors 68000


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


    Nov 23, 2007
    ...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