I am coding a Sudoku app on Xcode, and for each cell of the game I am pairing a label and a button, one of top of the other. When the user clicks the button, the number on the label will change. I thought a NSMutableDictionary would be handy to handle each of the button/label pairs, so I created one with the button as the key and the label as the value. To test the dictionary, I printed out the value to one of the buttons, but came out as null. Here is my code:
//Within my ViewController.h file
@property (weak, nonatomic) NSMutableDictionary *dictionary;
//Within my ViewController.m file
self.dictionary = [NSMutableDictionary dictionary];
//the (id<NSCopying>)self.A1Button is for casting purposes
[self.dictionary setObject: self.A1Label forKey: (id<NSCopying>)self.A1Button];
[self.dictionary setObject: self.A2Label forKey: (id<NSCopying>)self.A2Button];
[self.dictionary setObject: self.A3Label forKey: (id<NSCopying>)self.A3Button];
[self.dictionary setObject: self.A4Label forKey: (id<NSCopying>)self.A4Button];
[self.dictionary setObject: self.A5Label forKey: (id<NSCopying>)self.A5Button];
[self.dictionary setObject: self.A6Label forKey: (id<NSCopying>)self.A6Button];
[self.dictionary setObject: self.A7Label forKey: (id<NSCopying>)self.A7Button];
[self.dictionary setObject: self.A9Label forKey: (id<NSCopying>)self.A9Button];
NSLog(@"%@", [self.dictionary objectForKey:self.A2Button]);
What I get back is:
2015-12-28 05:44:49.940 Sudoku[6349:292670] (null)
Can anybody explain what is happening? Thanks!