Alex Rivera | Logout

Method overloading in Objective-C?

Asked 2010-02-18T04:31:17.093
135

As far as my knowledge, Objective-C does not support method overloading. What can be the alternative for this in Objective-C? Or should I always use different method name?

Edit
Report

1 Answer

200

Correct, objective-C does not support method overloading, so you have to use different method names.

Note, though, that the "method name" includes the method signature keywords (the parameter names that come before the ":"s), so the following are two different methods, even though they both begin "writeToFile":

-(void) writeToFile:(NSString *)path fromInt:(int)anInt;
-(void) writeToFile:(NSString *)path fromString:(NSString *)aString;

(the names of the two methods are "writeToFile:fromInt:" and "writeToFile:fromString:").

answered 2010-02-18T05:10:03.163

Your Answer