1

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!

David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98

1 Answers1

2

I found the answer my selfe:

NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
    NSString *port = [defaults stringForKey:@"port"];
    UInt16 portNumber = [[formatter numberFromString:port] unsignedShortValue];
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98