Search code examples
nsstringnsnumberiboutlet

Learning about NSNumber


if I`m getting a string from IBOutlet I use:

NSString *stringName = [[self IBOutletName] text];

but how can I get a value if it`s a number?


Solution

  • Here ya go:

    NSString * someNumberString = [[self IBOutletName] text];
    int someInt = [someNumberString intValue];
    

    Note, I'm sure there are more, but just asa starter, you can also use:

    float someFloat = [someFloatString floatValue]; // for floats
    double someDouble = [someDoubleString doubleValue]; // for doubles
    

    If you want the string value from an NSNumber just do:

    NSString * stringValue = [someNSNumber stringValue];