Method with multiple input parameters Method with multiple input parameters ios ios

Method with multiple input parameters


No. A method must have the format as you described:

- (void)first:(NSString *)fname second:(NSString *)mname third:(NSString *)lname;


You have to have the parameters interleaved with the method signature. It's ok because xcode has code completion and it can give you nice descriptive names about what your method is doing and what it requires.

e.g.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

In the example above without even looking at the API for UIViewController you can get a pretty good understanding of how this method works and what it's params are. It is good practice to name your methods well to describe what they do (it can remove the need for most commenting if done well).

You may well of course see a method written like this

- (void)myMethodThatAcceptsARectangle:(float)x :(float)y :(float)w :(float)h;

But this will not be very clear in use as to what the parameters relate to:

[self myMethodThatAcceptsARectangle:1.0f :1.0f :1.0f :1.0f];

So you should avoid this (I added it incase you ever see this and wonder what's happening).


fullName:(NSString, NSString, NSString) fname, mname, lname;

Yes, you can do something like that. It'd look like this instead:

-(void)fullName:(NSString*)fname :(NSString*)mname :(NSString*)lname

and you'd call it like this:

[foo fullName:first :middle :last];

That largely defeats the point of Objective-C's method names, though, and the main reason to do something like that is to register your dislike of the normal Objective-C convention, or perhaps to get yourself kicked off whatever project you're working on.