1

I've seen many answer on stackoverflow. All answer says method overloading not possible in objective c. But currently i've made a real example so its working for me. So i'm totally confused. May be i'm wrong but according to java concept i'm right. So any one make me more clear and any help will be very appriciated.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self show];
    [self show:@"Foo......"];
}

- (void)show
{
    NSLog(@"Show");
}

- (void)show:(NSString *)str
{
    NSLog(@"Str %@",str);
}

Output

Show

Str Foo......

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66

1 Answers1

2

In C++, you do it as int add(int, int) with int add(int, int, int). Both method have same name add

however in Obj-C your selector contains another name as add:first:withSecond: and add:first:withSecond:withThird:, here both the method have different name, isn't it?

So here your method name (selector) gets changed.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140