Contents (package MULK.OBJECTIVE-CL)


Function INVOKE-BY-NAME

Purpose:

Send a message to an Objective-C object by the name of the method.

Syntax:

invoke-by-name receiver method-name &rest args

Arguments and Values:

receiver --- an Objective-C wrapper object.

method-name --- a selector designator.

args --- a list of objects.

Returns: result --- the return value of the method invocation.

Description:

invoke-by-name is like invoke except in its syntax. It sends the message whose selector is designated by method-name, which must be either a string, a symbol, a list of message name components as in a call to invoke, or an object of type selector, to receiver.

Examples:

(invoke-by-name (find-objc-class 'ns-string)  
                '(:string-with-u-t-f-8-string) "Mulk.")  
  ;=> #<GSCBufferString `Mulk.' {5B36087}>  
  
(invoke-by-name (find-objc-class 'ns-object)  
                "self")  
  ;=> #<NSObject `NSObject' {16ECF598}>  
  
(invoke-by-name (find-objc-class 'ns-string)  
                "stringWithCString:encoding:"  
                "Mulk."  
                4)  
  ;=> #<GSCBufferString `Mulk.' {5B36087}>  
 

Note:

selector objects are funcallable. Therefore, the following calls are all equivalent:

(invoke-by-name instance "stringWithCString:encoding:" "Mulk." 4)  
(invoke instance :string-with-c-string "Mulk." :encoding 4)  
(funcall (selector "stringWithCString:encoding:") instance "Mulk." 4) 

In fact, using invoke-by-name is discouraged in favour of the latter form.

Rationale:

Whereas invoke tries to make writing as well as reading method invocations easy by interspersing method name components with arguments as Objective-C does, invoke-by-name is better suited for method selection at run time as well as code generation. It is also slightly easier to use with apply.

See also:

invoke