My code:
NSArray *keys = [piecesDict allKeys];
//keys are NSStrings of sprite names, piecesDict is NSDictionary
for(int i = 0; i < piecesDict.count; i++){
PuzzlePiece *piece;
id key = [keys objectAtIndex:i];
piece.keyName = key; }
The exact code that crashes is piece.keyName = key. I get EXC_BAD_ACCESS. The .keyName property is (nonatomic, retain). I have tried making key an NSString * or casting it with (NSString *)key to no avail.
What am I missing here?
You don’t initialize
piece, you just declare a pointer and leave it hanging in the air. It will point to random crap and crash. You need to assign it to a proper instance:And seriously: do learn C well before attempting to make iOS apps or you will shoot yourself and your users in the foot.