It must be one of those things where there’s a tiny mistake i’ve missed, or something, but i can’t seem to figure it out.
Viewcontroller.h
#import "RGBEditView.h"
@interface ColorPickerView : UIViewController {
RGBEditView *rgbEditView;
}
-(void)showRGBEditor;
.m
-(void)showRGBEditor {
rgbEditView = [[RGBEditView alloc] initWithFrame:CGRectMake(0, 0, 280, 46) H:h S:s B:b];
}
It’s this line above, the initwithframe line, that gives the error 'Incompatible Objective-C types assigning '*', expected '*'
RGBEditView.h
@interface RGBEditView : UIView {
}
-(RGBEditView *)initWithFrame:(CGRect)frame H:(float)hue S:(float)saturation B:(float)brightness;
RGBEditView.m
-(RGBEditView *)initWithFrame:(CGRect)frame H:(float)hue S:(float)saturation B:(float)brightness {
[super initWithFrame:frame];
return self;
}
Can anybody see my problem? I’m very confused about this.
EDIT:
The problem lies in that I have another class which also uses initWithFrame:H:S:B:, so the only way to fix this is to change on of them to something a bit different, but this seems like an awkward work around. Any other solutions?
the methods
initand methods that start withinitWithshould return typeid.what typically happens is that you have 2 classes with the same method name (initializer in this case), but differ in their return types:
RGBEditView
HSBEditView
allocreturns id – the compiler warns you because it sees an expression which resembles type assignment used in the following example:you correct this by returning
idfrom your initializers, like this:you return id to avoid clashes like this, and because the compiler doesn’t know what type is returned via
alloc, so every subclass declaration would have to return a different type – which would only lead to more problems.the exception to this is to use well qualified names – and is typically seen in convenience constructors: