0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Use the rangeValue method:

NSRange range = [linkData rangeValue]; // assume linkData is NSValue
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • it's done. i do not realized the id including so many methods itself before; thanks! – user4246451 Jan 07 '15 at 03:36
  • `id` doesn't include any methods really. `rangeValue` is being called on an instance of `NSConcreteValue`. – rmaddy Jan 07 '15 at 03:37
  • do you mean that the method is work in the NSConcreteValue? when i type "[id " in the xcode,it prompts many method,but how the xcode knows what kind of method i can use? – user4246451 Jan 07 '15 at 03:45
  • 1
    It doesn't with `id`. `id` could be anything as far as Xcode knows. If you use a method that doesn't exist on the actual object, your app will crash with an "unknown selector" error. – rmaddy Jan 07 '15 at 03:51