Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert NSString into CGPoint in iPhone

I am getting the values from UITextfield into NSString , need to convert the values of NSString into CGPoint, Suppose if i enter 6,5 into textfield it should covert it into CGPoint.

like image 761
Kashif Avatar asked Nov 02 '11 10:11

Kashif


People also ask

What is NSString in swift?

A static, plain-text Unicode string object that bridges to String ; use NSString when you need reference semantics or other Foundation-specific behavior.

What is NSString in objective c?

(NSString *) is simply the type of the argument - a string object, which is the NSString class in Cocoa. In Objective-C you're always dealing with object references (pointers), so the "*" indicates that the argument is a reference to an NSString object.


1 Answers

See CGPointFromString (documentation in link). The string has to be in the format {x,y} so you would need to add those to the user input yourself:

CGPoint myPoint = CGPointFromString([NSString stringWithFormat:@"{%@}",textField.text]);

Will return CGPointZero if the string is invalid.

like image 116
jrturton Avatar answered Oct 05 '22 23:10

jrturton