Reputation: 3545
I am facing the problem, that I can't convert an string or an int to an UInt16. This is my current code: (UInt16)[[defaults stringForKey:@"port"] intValue]
[[defaults stringForKey:@"port"] intValue]
is 8080
and (UInt16)[[defaults stringForKey:@"port"] intValue]
becomes 51075
which is wrong. Does anyone know to do this?
Thanks for your help!
Upvotes: 1
Views: 1520
Reputation: 3545
I found the answer my selfe:
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
NSString *port = [defaults stringForKey:@"port"];
UInt16 portNumber = [[formatter numberFromString:port] unsignedShortValue];
Upvotes: 2