Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate Method Names - Objective-c

Why does this compile with out any errors or warnings?

@interface ObjectTest : NSObject {

}
-(void)iAmADoubleMethod;
-(void)iAmADoubleMethod;
@end

@implementation ObjectTest
-(void)iAmADoubleMethod {
    NSLog(@"IAmADoubleMethod");
}
@end

I came across this in a project I am working on. I come from a C++ background, so I figure I would get at least a warning for this. Not only would I like to know why it complies but could this code cause any problems?

Thanks.

like image 639
NixonsBack Avatar asked Nov 25 '25 21:11

NixonsBack


1 Answers

You're just declaring the method twice. The declarations don't conflict, so it's not a problem. It's the same as if you'd declared a function multiple times in a plain C or C++ program.

like image 160
Chuck Avatar answered Nov 28 '25 12:11

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!