Multiple Arguments to Methods
Let’s continue to work with the Fraction
class and make some additions. You have defined six methods. It would be nice to have a method to set both the numerator and the denominator with a single message. You define methods that take multiple arguments simply by listing each successive argument followed by a colon. This becomes part of the method name. For example, the method named addEntryWithName:andEmail:
takes two arguments, presumably a name and an email address. The method addEntryWithName:andEmail:andPhone:
takes three arguments: a name, an email address, and a phone number.
A method to set both the numerator and the denominator could be named setNumerator:andDenominator:
, and you might use it like this: ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.