No, not in this case. The method in the example returns the score. You would consider using / returning an NSNotFound (for example) method that returns an index, where 0 also a valid index and therefore a distorting result.
So yes, you should just return 0, and the return type should be unsigned (NSUInteger) ", since NSNotFound should not be related to counting. It really covers your affairs, regardless of the magic value.
If you prefer to know where the problem is (and I do it myself quite often), I find it preferable to just consider this a programmer error to call the method when the collection is empty.
justin
source share