chickadee » objc » objc:define-method

(objc:define-method CLASS RT ARGS . BODY)syntax
(objc:define-class-method CLASS RT ARGS . BODY)syntax

Define an instance or class method in CLASS.

CLASSAn objc:class object representing the destination class.
RTThe return type of the method.
ARGS((KEYWORD TYPE VAR-NAME) ...) or SYMBOL
BODYBody of a lambda comprising the method. The parameters visible inside the lambda are self (a class or instance object), sel (the method selector), and the arguments given in ARGS.

Each list in ARGS adds a method argument of type TYPE, visible to the method body as VAR-NAME. As in Objective C, each argument is associated with a KEYWORD and each KEYWORD is combined into a method name. Hyphenated keywords are accepted, just like in method invocations. A bare SYMBOL can be used as the method name (instead of a list) if no arguments are expected.

TYPE should be a short typename, a symbol such as INT.

Within a method body, you can use (@ super ...) to call a class or instance method of the superclass. Note: super is a reserved keyword, not a variable.

Example:

 (objc:define-method Rect VOID ((set-width: DBL my-w)
                                (height:    DBL my-h))
   (ivar-set! self w my-w)
   (ivar-set! self h my-h))

Method removal is not yet implemented, but redefining a method will override the old definition.