Search code examples
iosobjective-coverloadingdynamic-binding

Function Overloading in Objective-C?


C experts as per my understanding Objective-C is a dynamic binding language which not allowed to overload any method in a class.

But one thing irritating me if I write two methods with the same name but a different number of parameters list like:

 // Which is not allowed in objective-c

 -(void)updateValue:(int)intVal{

  } 

 -(void)updateValue:(float)floatVal{

  }

But the second case which Objective-C allowing is:

 // Allowed in Objective-C

 -(void)updateValue:(int)intVal{

   }

 -(void)updateValue:(float)floatVal :(int)intVal{

   }

Although both cases are Method overloading.

Now my question is why the second case is allowed.

Is the method with two params in the second case changing the Method Name ? or something else ?

Kindly explain.


Solution

  • Is the method with two params in the second case changing the Method Name ?

    Yes. A method name is the compound of all its parameter prefixes including the colons. So your two methods are updateValue: and updateValue::.

    HTH