I have multiple arrays, however, they are not retaining their data for use in another method.
Here's how I have it set up (simplified)
.h
NSArray *array;
@property (nonatomic, copy) NSArray *array;
-(void)someMethod:(NSArray*)someArray;
-(void)heresNewMethod;
.m
-(void)someMethod:(NSArray*)someArray
{
array = [someArray copy];
}
-(void)heresNewMethod //gets called by method not shown
{
NSLog(@"%@", array);
}
One of two things happened:
someMethod:
message, passingnil
(probably without meaning to). A message tonil
returnsnil
, so you assignednil
—as the result of thecopy
message—to thearray
instance variable. Even if you had stashed a pointer to an array there previously, you replaced it withnil
in your response to thissomeMethod:
message.someMethod:
message. Since instance variables are initialized tonil
, and you never put anything different in thearray
instance variable, it still containsnil
.Sprinkle more NSLog statements in your code to test the first theory. The truth is either one or the other, so confirming the first theory disproves the second, and vice versa.