hlily hlily - 10 days ago 5x
Objective-C Question

Is there a situation that when range.location > targetString.length, range.length !=0

  1. Is there a situation possible that when
    range.location > targetString.length
    range.length !=0

  2. What's the best way to judge whether an range variable exists?


An invalid NSRange has the location member set to NSNotFound (which is NSIntegerMax), so:

  1. Yes, when the range is invalid, however in that case the length member should be ignored anyway.
  2. If by "exists" you mean "valid", it's when location != NSNotFound.