// 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(UIGraphicsGetCurrentContext(), [myStroke endX], [myStroke endY]);
Your problem is you’re making your coordinates, pointers to
CGFloatand notCGFloattypes. They are not object types.CGfloatis currently, do not rely on this in the future just a type alias tofloat, 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: