• 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: multiple definitions of compare: -- design flaw?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple definitions of compare: -- design flaw?


  • Subject: Re: multiple definitions of compare: -- design flaw?
  • From: James Quick <email@hidden>
  • Date: Thu, 10 Jul 2003 15:13:37 -0400

On Thursday, July 10, 2003, at 01:21 PM, Brent Gulanowski wrote:

This is exactly my point: I AM writing another class that implements compare -- only it's actually comparing items in a dictionary which could be strings or numbers. I did not say that I wanted to compare objects of different classes, only that I wanted to avoid the compiler warning. Clearly one would want to ensure that one did not call -compare: on NSString with anything but another NSString! But the same program might want to compare two strings, two dates, two numbers or two custom objects, without having an annoying compiler warning about multiple declarations. Creating a warning when you aren't doing anything wrong is ... or might be ... a bug.

The warning is useful alerting you to a possible runtime mismatch. It is quite easy to quiet the warning.

Let's say your front end takes arguments as type id.
Your class determines the comparison argument arg1 must be sent to an NSString comparison
method. When you pass arg1 to a method expecting a string you will simply use a typecast
operation to declare the type. This would look like [aString compare: (NSString *) arg1].

Obviously, you should not quiet the compiler with typecasts all the time. Often they will
signal possible flaws in a design, or indicate a situation which might cause a problem.
In your case, it appears to be a well thought out solution, and a typecast is just what
you need to indicate to the compiler that you are aware you are passing a parameter
which is appropriate, even though by context alone the compiler thought it might
not be correct.
_______________________________________________
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.
References: 
 >Re: multiple definitions of compare: -- design flaw? (From: Brent Gulanowski <email@hidden>)

  • Prev by Date: Re: multiple definitions of compare: -- design flaw?
  • Next by Date: Re: Creating Really Big TIFF's
  • Previous by thread: Re: multiple definitions of compare: -- design flaw?
  • Next by thread: RE: multiple definitions of compare: -- design flaw?
  • Index(es):
    • Date
    • Thread