nil is a pointer, but length is an integer, so a warning to the compiler. You can compare length to 0 , but then this is a legitimate value for length in NSRange . If I needed a “not yet initialized” value for currentRange , I would decide to set it:
{ .location = NSNotFound, .length = 0 }
at -init . This, of course, suggests that a range can never accept this value during operations. If a range can really take any values in its domain, then you cannot use any of them as a placeholder for "not yet initialized".
You can choose to keep a pointer to a range that is NULL until the range is set. Another option would be to use a state template to distinguish between states before and after the range is set. Another is the development of the class and its interface, so that the range is only ever used after its installation.
user23743
source share