• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Casting (was: NSCalendarDate from plist)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Casting (was: NSCalendarDate from plist)
      • From: Ondra Cada <email@hidden>
References: 
 >Re: NSCalendarDate from plist (From: Kurt Revis <email@hidden>)
 >Re: NSCalendarDate from plist (From: "Erik M. Buck" <email@hidden>)
 >Casting (was: NSCalendarDate from plist) (From: Ondra Cada <email@hidden>)

  • Prev by Date: Casting (was: NSCalendarDate from plist)
  • Next by Date: Re: Casting (was: NSCalendarDate from plist)
  • Previous by thread: Casting (was: NSCalendarDate from plist)
  • Next by thread: Re: Casting (was: NSCalendarDate from plist)
  • Index(es):
    • Date
    • Thread