Re: Casting (was: NSCalendarDate from plist)
Re: Casting (was: NSCalendarDate from plist)
- Subject: Re: Casting (was: NSCalendarDate from plist)
- From: "Erik M. Buck" <email@hidden>
- Date: Sun, 25 Nov 2001 16:31:48 -0600
>
if ([(NSString*)[a objectAtIndex:n] compare:o]<0) ....
The problem with a cast like the above is that the programmer may not know
that [a objectAtIndex:n] is really an NSString instance.
Even still, the same can be done without a cast as follows even though it
amounts to the same thing and is equally unsafe:
{
NSString *tempString = [a objectAtIndex:n];
if([tempString compare:o] < 0) ...
}
The real issue/problem is that there are three or four different -compare:
methods that accept different incompatible types which causes the compiler
to emit a warning and pick one. The cast or the assignment is used to make
the compiler shut up and pick the correct -compare:
Who wants to file a bug or feature request ?
The
-(NSComparisonResult)compare:(NSNumber *)aValue,
-(NSComparisonResult)compare:(NSDate *)aValue, and
-(NSComparisonResult)compare:(NSString *)aValue
methods should all be changed to
-(NSComparisonResult)compare:(id)aValue.
For the type using versions there should be
-(NSComparisonResult)compareNumber:(NSNumber *)aValue,
-(NSComparisonResult)compareDate:(NSDate *)aValue, and
-(NSComparisonResult)compareString:(NSString *)aValue methods.