Incompatible type in Objective C Iphone SDK 4.0
// CStroke.h #import
@interface CStroke : NSObject {
CGFloat *startX;
CGFloat *startY;
CGFloat *endX;
CGFloat *endY;
BOOL *state;
}
@property CGFloat *startX;
@property CGFloat *startY;
@property CGFloat *endX;
@property CGFloat *endY;
@property BOOL *state;
-(void)setStroke: (CGFloat *)newStartX andStartY:(CGFloat *)newStartY andEndX:(CGFloat *)newEndX andEndY:(CGFloat *)newEndY;
@end
After set up CStroke class, I am going to use it in ViewController to draw something out using CGFloat
CGFloat *startX = (CGFloat *)[[self retrieveStartCoordinateOfStroke:k whichKindOfCoorXOrY:@"X"] integerValue];
CGFloat *startY = (CGFloat *)[[self retrieveStartCoordinateOfStroke:k whichKindOfCoorXOrY:@"Y"] integerValue];
CGFloat *endX = (CGFloat *)[[self retrieveEndCoordinateOfStroke:k whichKindOfCoordXOrY:@"X"] integerValue];
CGFloat *endY = (CGFloat *)[[self retrieveEndCoordinateOfStroke:k whichKindOfCoordXOrY:@"Y"] integerValue];
CStroke *stroke = [[CStroke alloc] init];
[stroke setStroke:startX andStartY:startY andEndX:endX andEndY:endY];
This is where I got error...I can't figure out what happened...are they both CGFloat type...Any answer for this? The error is incompatible type for argument 2 of 'CGContextAddLineToPoint' and incompatible type for argument 2 of 'CGContextMoveToPoint'
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), myStroke.startX, myStroke.startY);
CGContextAddLineToPoint(UIGraphicsGetCurrentConte开发者_如何学Pythonxt(), [myStroke endX], [myStroke endY]);
Your problem is you're making your coordinates, pointers to CGFloat
and not CGFloat
types. They are not object types. CGfloat
is currently, do not rely on this in the future just a type alias to float
, and the functions you're passing to eventually, expect the scalar values, not pointers.
On a secondary note, getting the current graphics context is not a cheap operation. Do it once. That is, change your code to look something like this:
CGContextRef context = UIGraphicsGetCurrentContext();
// Now pass in context where you would normally pass in UIGraphicsGetCurrentContext()
I'm not sure I really understand what you are trying to do, but I don't really think you really meant to use pointers to floats... try using just float and not pointers:
//CGFloat *startX; no need for it to be a pointer
CGFloat startX; // just a regular CGFloat is enough
//change all your variables to be CGFloats and not pointers to CGFloats
精彩评论