Search This Blog

Thursday, March 4, 2010

Multiple Arguments Objective-C

Side note: The @ symbol at the front of @”Testing” string is convenience method that converts the given string to an NSString object, which in the case of the setStr method, is the required type for the parameter.

Multiple Arguments
Taking this another step further, we can pass multiple arguments along with our message. The message below takes three arguments, a string, date and integer. Sometimes it easier to read the method aloud to get this jist of what’s up. In this case, “pass a message to the ptr receiver that sets a string, and a date and an integer.”

[ptr setStr:@"A new test..." andDate:[NSDate date] andInteger:99];


Here is how we define the message in the interface file:

-(void) setStr:(NSString *)str andDate:(NSDate *)date andInteger:(int)x;


And here is the implementation of the setStr() method which accepts three arguments:

-(void) setStr:(NSString *)strInput andDate:(NSDate *)dateInput
andInteger:(int)xInput
{
[self setStr:strInput];
[self setDate:dateInput];
[self setX:xInput];
}

No comments:

Post a Comment