• 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: Future Objective-C changes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Future Objective-C changes


  • Subject: Re: Future Objective-C changes
  • From: Prachi Gauriar <email@hidden>
  • Date: Fri, 16 May 2003 02:06:18 -0500

On Friday, May 16, 2003, at 01:16 AM, David Cittadini wrote:

With regards to method overloading, I thought it may be useful to be able to say:

-(int)doSomethingWithFoo:(Foo*)y;
-(int)doSomethingWithFoo:(int)y;

With method overloading the compiler could resolve most of the parameter type issues without me having to create different method names just because the parameter type is different.

Don't forget, unlike C++/Java, Objective C is weakly-typed. Because of this, the need for method overloading is often unnecessary. You could always do something like

- (int)doSomethingWithFoo:(id)foo
{
if ([foo isKindOfClass:[SomeClass class]]) {
[foo doThis];
} else if ([foo isKindOfClass:[SomeOtherClass class]]) {
[foo doThisInstead];
}

return anInt;
}

If you wrap an int or other C primitive in an Obj-C wrapper, like NSNumber, you can do this pretty easily. Of course, if you have a different number of arguments, your method name is different anyway. As the number of args increases, this doesn't get too much worse, though it is definitely more of a pain than in C++ or Java. You don't detect this at compile time, but you avoid runtime problems too.

-Prachi
_______________________________________________
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: Future Objective-C changes (From: David Cittadini <email@hidden>)

  • Prev by Date: Re: Future Objective-C changes
  • Next by Date: Re: Best way to create custom DMG's
  • Previous by thread: Re: Future Objective-C changes
  • Next by thread: Re: Future Objective-C changes
  • Index(es):
    • Date
    • Thread