I\'m having trouble converting a string into an integer. I googled it but all I can find is how to convert an int into a string. Does anyone know how to do it the other way
You can also use like :
NSInteger getVal = [self.string integerValue];
Swift 3.0:
Int("5")
or
let stringToConvert = "5"
Int(stringToConvert)
NSString *string = /* Assume this exists. */;
int value = [string intValue];
Very easy..
int (name of integer) = [(name of string, no ()) intValue];
I had to do something like this but wanted to use a getter/setter for mine. In particular I wanted to return a long from a textfield. The other answers all worked well also, I just ended up adapting mine a little as my school project evolved.
long ms = [self.textfield.text longLongValue];
return ms;