Search code examples
iosios5core-foundationnsvalue

Getting an int out of NSConcreteValue / NSValue


I am trying to extract an int inside of a NSValue / NSConcreteValue instance. I tried to cast them this way, but it didn't work:

    NSValue *toValue = (NSValue *)someValue;
    NSNumber *toNumber = (NSNumber*)toValue;
    int final = [toNumber intValue];

I also tried using getValue but that also didn't work for me.


Solution

  • Are you sure an int was saved into it? If yes you might get it with:

    int final = 0;
    [someValue getValue:&final];
    

    you know you can ask a NSValue its type with

    [value objCType]
    

    which returns a const char *

    cheers, Jörg