Skip to content Skip to sidebar Skip to footer

Objective-c Appdelegate Array

I'm creating a SQLite application, with two simple views. I have two arrays in SQLAppDelegate: - (void)applicationDidFinishLaunching:(UIApplication *)application { NSMutableAr

Solution 1:

self.modelArray = tempArray;self.detailArray = tempArray;

Here both your instance variable arrays contain pointer to the same NSMutableArray instance (assuming that your property has retain attribute), so changes to the one of the iVars are also applied to another one (as they point to the same object).

To fix that initialize your arrays with different NSMutableArray's:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    self.modelArray = [NSMutableArray array];
    self.detailArray = [NSMutableArray array];
    ...

Solution 2:

Your assigning the same NSMutableArray object to the two different variables.

What you want is to create 2 temp arrays and use them.

Solution 3:

What really happens is that you create an actual array in the first line, but in the next two you make modelArray and detailArray point to the same real in-memory array you created before. Thus, whenever you modify the first one, the second one is still pointing there and is not a separate copy.

Post a Comment for "Objective-c Appdelegate Array"