I'm currently working on a Sudoku application, the numbers are stored within a Multi-Dimensional NSMutableArray of NSNumbers. I keep an array in my SudokuGridView, for displaying the numbers in the grid. When it comes time to solve the puzzle, I pass a [grid numberGrid] to a subclass of NSOperation I've created that solves the puzzle.
The grid's array is defined as a property as such:
@property (readonly) NSMutableArray *numberArray;
When passing it to the sudoku grid solver I go:
MESudokuSolver *solvePuzzleOperation = [[MESudokuSolver alloc] initWithPuzzle: [grid numberArray]];
initWithPuzzle is defined as so:
- (id)initWithPuzzle:(NSMutableArray *)puzzleArray {
if(self = [super init]) {
puzzle = [[NSMutableArray alloc] initWithArray: puzzleArray];
}
return self;
}
When I then convert the puzzle to a primitive int array to solve it, and then back into the puzzle NSMutableArray. What's funny, is that now, the grid's NSMutableArray now has the solution... Which means that somehow inside the MESudokuSolver the grid's array is being modified. So I did some investigation, the pointer to the array that is passed into the MESudokuSolver instance is different than the MESudokuSolver's puzzle NSMutableArray. Strange, right? I know.
Upon FURTHER investigation, the pointer to the NSNumbers inside the arrays with different pointers are actually the SAME.
To you StackOverflow, I ask, WTF?