View Full Version : NSArray may not respond to '-length'

Feb 23, 2011, 08:47 PM
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.

Feb 23, 2011, 09:23 PM
It's not length. It's count. Make sure you read the sdk documentation, it would have quickly answered this.

Feb 23, 2011, 09:48 PM
...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.