Re: [Q] Calling isEmpty on an NSRange?
Re: [Q] Calling isEmpty on an NSRange?
- Subject: Re: [Q] Calling isEmpty on an NSRange?
- From: Simon Stapleton <email@hidden>
- Date: Tue, 24 Sep 2002 14:35:28 +0200
Ando Sonenblick <email@hidden> wrote:
OK... So a range seems to be a mere struct and not a class
instantiation.
Cool: I know I can get its length, location, etc via:
Length and location. There is no etc ;-)
{
NSRange range;
range = [editor selectedRange];
return range.length;
}
But I've tried every which way to call isEmpty (and the other
"actions")
with a range, but always get compile errors...
Can anyone elucidate?
You won't be able to use any object methods on it, as it is, as you
noticed, a mere struct. Thusly, you will need to go back to C.
If you're using NSRange's returned by the various cocoa methods, the
convention is that an invalid range is flagged by returning a range of
(NSNotFound, 0).
Thus you might get an empty range (length is zero) with a valid
location (insertion point springs to mind here), but a real invalid
range such as that returned by a search routine that has failed will
always have its location as NSNotFound.
Therefore to check for a valid but empty range, use
(aRange.location != NSNotFound) && (aRange.length == 0)
and to check for an invalid range, simply use
(aRange.location == NSNotFound)
Hope that helps.
Simon
--
PGP Key Id : 0x50D0698D
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.