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