I've tried to search through these and other forums but i cannot figure out how to create an array.
I've tried to search through these and other forums but i cannot figure out how to create an array.
What do you mean "set it up"? Define it? Populate it? What?i know that but how do i set it up?
I mean put objects into the array to be accessed later, like numbers or strings.
You've looked through the NSArray Class Reference, right? Is there something in particular you don't understand? Rather than give you the outright answer (which would be very easy), we're trying to guide you to educate yourself, a very handy skill to have!I mean put objects into the array to be accessed later, like numbers or strings.
NSArray *array = [NSArray arrayWithObjects: @"John", @"Bob", [NSNull null], @"Jane"];
Where do you need to access this array?Now my main question is where do I declare this...
The NSNull usage in that declaration should give you a hint....and also how do I put an NSNumber into an array like this one which just uses strings?
Where do you need to access this array?
The NSNull usage in that declaration should give you a hint.
NSNumber *N1 = [numberWithInt:1];
NSNumber *N2 = [numberWithInt:2];
NSArray *Myarray = [NSArray initWithObjects:N1,N2,nil];
In multiple methods?in the .m viewController
Close. Your previous example used arrayWithObjects: Do you understand why? You can use initWithObjects: if you like, but there will be something else you'll need to do to your array first. Do you know what it is?So like this?
Code:NSNumber *N1 = [numberWithInt:1]; NSNumber *N2 = [numberWithInt:2]; NSArray *Myarray = [NSArray initWithObjects:N1,N2,nil];
In multiple methods?
Close. Your previous example used arrayWithObjects: Do you understand why? You can use initWithObjects: if you like, but there will be something else you'll need to do to your array first. Do you know what it is?
Yes, but a single view controller can contains multiple methods. If you only need access to it from within one method, declare and init your array in that method. If you need access to it from multiple methods, either declare it as a static or an instance variable, accordingly.No it's just going to be used in one view controller
Ding Ding Ding! We have a winner! Good job!Do I need to allocate it?
You're welcome. Appreciate the feedback.Thank you so much for helping me through this one rather than telling me the answer, really helped alot!