I found a method to convert String to NSNumber, but the code is in Objective-C. I have tried converting it to Swift but it is not working.
The code I am using:
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *myNumber = [f numberFromString:@"42222222222"];
and in Swift I am using it in this way:
var i = NSNumberFormatter.numberFromString("42")
But this code is not working. What am I doing wrong?