This is really baffling me...
I've got a class like so:
Code:
@interface DColor : NSObject {
CGFloat _red, _green, _blue;
CGFloat _alpha;
}
@property (readwrite, assign) CGFloat red;
@property (readwrite, assign) CGFloat green;
@property (readwrite, assign) CGFloat blue;
@property (readwrite, assign) CGFloat alpha;
-(DColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
@end
However, later on, I have an initializer for another class like so:
Code:
#import "DColor.h"
@interface TimelineSection : NSObject {
DColor *_dcolor;
}
@property (retain, readwrite) DColor *dcolor;
@end
@implementation UseDColor
@synthesize dcolor=_dcolor;
-(id)init {
self = [super init];
if( self ) {
/* Attempt 1 */
d = [[DColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
/* Attempt 2 */
[self setDcolor:[[DColor alloc] initWithRed:1.0f
green:1.0f
blue:1.0f
alpha:1.0f]];
/* Attempt 3 */
self.dcolor = [[DColor alloc] initWithRed:1.0f
green:1.0f
blue:1.0f
alpha:1.0f];
/* Attempt 4 */
self.dcolor = [[[DColor alloc] initWithRed:1.0f
green:1.0f
blue:1.0f
alpha:1.0f] autorelease];
}
}
@end
Here's the strange thing... both Attempt 1-3 are issuing me compiler warnings:
Quote:
|
warning: incompatible Objective-C types assigning 'struct UIColor *', expected 'struct DColor *'
|
I end up having to do something weird like this to remove it:
Code:
DColor *d;
d = [DColor alloc];
d = [d initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
Or I just realized, Attempt #4 resolves the compiler warning as well. Is this normal behavior? Should I always be assigning with autorelease there?
Clearly it's conflicting with the UIColor implementation of initWithRed.. But why would it be confused like that? Can anyone explain what's going on and the proper fix for this?
Incidentally, if I put an NSLog() in the actual initWithRed method, it does get invoked. So clearly it's calling the right thing, even if it's a bit confused about it.
Thanks