2

I have this objective-c code, but I cant find the size of the allocated array.

NSArray *myArray = [[NSArray alloc] initWithObjects:@"Apple", @"Orange", @"Banana",      @"Plum", nil];
[myArray objectAtIndex: 0];
[myArray length];

XCode give-me this error:

"No visible @interface for "NSArray" declares the selector length"

What can this be?

2 Answers2

1

What is length? If you want to find the number of objects in the array use:

[myArray count];

If you want to find the size, check this link out:

Length of an Array in Objective C

Community
  • 1
  • 1
MCKapur
  • 9,127
  • 9
  • 58
  • 101
  • It worked, thank you. Strange a little this logic, about counting the number of objects, instead of characters. –  Dec 19 '12 at 13:46
0

@Sedate Alien is right. [myArray count] or myArray.count are the ways to get the length.

It looks like you might be missing something simple like the framework containing NSArray ... not sure how, since most templates include it, but just in case make sure you have #import <Foundation/Foundation.h> and added the actual framework to your project

Roughly: (Project->Build Phases->Link Binary With Libraries... -> "+" button->Foundation)

Miles Alden
  • 1,542
  • 1
  • 11
  • 21