I have a class defined where the top two properties are accessible without issue. Only the UIColor* is a problem. I imagine something isn’t being alloc’d, init’d, retained, or released properly and have been changing various things without success. Any help would be grand.
// PieceScore.h
@interface PieceScore : NSObject {
int pieceCount;
BOOL greatMatch;
UIColor *colorMatched;
}
@property (nonatomic) int pieceCount;
@property (nonatomic) BOOL greatMatch;
@property (nonatomic, retain) UIColor *colorMatched;
-(id) initWithPieceCount:(int)pC withGreatMatch:(BOOL)gM withColorMatched:(UIColor*)cM;
@end
// PieceScore.m
@implementation PieceScore
@synthesize pieceCount, greatMatch, colorMatched;
-(id) init {
return [self initWithPieceCount:0 withGreatMatch:NO withColorMatched:[UIColor clearColor]];
}
-(id) initWithPieceCount:(int)pC withGreatMatch:(BOOL)gM withColorMatched:(UIColor*)cM {
self = [super init];
if (self) {
pieceCount = pC;
greatMatch = gM;
colorMatched = cM;
}
return self;
}
@end
It is initialized and returned by another class as follows:
PieceScore* pieceScore = [[[PieceScore alloc] initWithPieceCount:piecesRemoved withGreatMatch:greatMatch withColorMatched:pieceColor] autorelease];
return pieceScore;
NOTE: (pieceColor is a UIColor*)
Then, the UIColor* is used in a method of yet another class:
- (void) labelRender:(UILabel*)label withColor:(UIColor *)color {
// ...
label.textColor = color; // Thread 1: Program received signal: "EXC_BAD_ACCESS".
// ...
}
In the debug view, I can see that color is actually being passed as a UIColor*, but is error-ing out when being assigned to the label’s textColor property.
You are setting the ivar to an autoreleased variable. Make sure you use the property so that it is properly retained.
Change
colorMatched = cM;toself.colorMatched = cM;