Search code examples
iosobjective-cnsrangensvalue

How to get a NSRange Value from NSConcreteValue?


The code is like this. My question is how to get the NSRange value from the id type?

-(void)clicText:(MyLabel *)label clickedOnLink:(id)linkData{
     NSString *message = [NSString stringWithFormat:@"LinkData is %@:%@",[[linkData class] description],linkData];
}

I get the type is NSConcreteValue and the data value is NSRange:{0,4}; but how do I get the NSRange from the NSConcreteValue?

I have already tried the [NSValue valueWithNonretainedObject:linkData]; but it does not make sense.


Solution

  • Use the rangeValue method:

    NSRange range = [linkData rangeValue]; // assume linkData is NSValue