I have read countless questions surrounding the copying of arrays on both this site and others, but none directly addresses the problem I'm having.
I have declared and synthesized a property called arrXTurbulenceValues:
@property (weak, nonatomic) NSArray *arrXTurbulenceValues;
@synthesize arrXTurbulenceValues;
I am initializing the array in the ViewDidLoad() method:
self.arrXTurbulenceValues = [[NSArray alloc] init];
Some processing occurs in a method, where values are stored to a NSMutableArray. At the end of that processing, I am trying to deep copy the NSMutableArray into the NSArray property, via this code:
self.arrXTurbulenceValues = [[NSMutableArray alloc] initWithArray:tempXvalues copyItems:YES];
The copy fails, and self.arrXTurbulenceValues remains nil. There are 1900+ NSString objects contained in the tempXvalues array that I am trying to copy.
What am I doing wrong? I have tried the copying code with & without the initialization in ViewDidLoad(), and I've also tried configuring the property as both an NSArray and NSMutableArray.
Does NSString respond to NSCopying? It appears to, if I'm reading the docs correctly.
The iOS environment coupled to Objective C is a nightmare. I've never seen anything so finicky to deal with. Ugh.
Assuming that you are running in ARC, try changing the "weak" to a "strong":
into:
At the end of your -viewDidLoad method, there are no more strong references to the array, and it is deallocating (which also nils out all weak references to it)