Problems Converting CGPoint to String

I'm having trouble converting CGPoint to string. I tried various methods, but it seems the most promising, but it still won't work. Any suggestions?

Here is my code:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; coord = [touch locationInView:touch.view]; viewcoord.text = [NSString stringWithFormat:@"coordinates %@", coord.x, coord.y]; 

I get the output, but it just says "null" and I don’t understand why ...

thanks

+4
source share
2 answers
 viewcoord.text = [NSString stringWithFormat:@"coordinates %@", NSStringFromCGPoint(coord)]; 
+14
source

The format string uses %@ , which applies only to objective-C objects. It looks like you are trying to print not one, but two values ​​(x and y), both of which are floats. Try the following:

 viewcoord.text = [NSString stringWithFormat:@"coordinates %f, %f", coord.x, coord.y]; 
+1
source

Source: https://habr.com/ru/post/1313224/


All Articles