Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSSelector

Inherits from
Object
Package
com.apple.cocoa.foundation
Companion guide

Overview

An NSSelector object (also called a selector) specifies a method signature, which is a method’s name and parameter list. You can later apply a selector on any object, and it performs the method that matches the selector, if there is one.

NSSelector is the Java implementation of the Objective-C type SEL, described in the “Selectors” section of The Objective-C Programming Language.

For details on using NSSelector, see “Method Selectors” and “Using NSSelector”.

Tasks

Constructors

Invoking a Selector

Accessing Information About a Selector

Constructors

NSSelector

Deprecated.

public NSSelector(String methodName)

Creates a selector for the method that's named methodName and takes parameters parameterTypes.

public NSSelector(String methodName, Class[] parameterTypes)

Discussion

To create a selector for a method that takes no arguments, use null for parameterTypes. For an example, see “Using NSSelector”.

Static Methods

invoke

public static Object invoke(String methodName, Class[] parameterTypes, Object target, Object[] arguments)

Discussion

Creates and applies a selector that has any number of arguments. This method creates a selector with methodName and the parameter types in the array parameterTypes, applies that selector to target with the arguments in the array arguments, and returns the result. To apply a method that takes no arguments, use null for the arrays parameterTypes and arguments. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke. For more information, see those method descriptions.

public static Object invoke(String methodName, Class parameterType, Object target, Object argument)

Discussion

Creates and applies a selector that has one argument. This method creates a selector with methodName and parameterType, applies that selector to target with argument, and returns the result. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke. For more information, see those method descriptions.

public static Object invoke(String methodName, Class parameterType1, Class parameterType2, Object target, Object argument1, Object argument2)

Discussion

Creates and applies a selector that has two arguments. This method creates a selector with methodName and the parameter types parameterType1 and parameterType2, applies that selector to target with the arguments argument1 and argument2, and returns the result. As part of its implementation, this method uses the NSSelector constructor and the instance method invoke. For more information, see those method descriptions.

Instance Methods

equals

Returns whether anObject equals the method that matches the receiver.

public boolean equals(Object anObject)

implementedByClass

Returns whether the class targetClass implements a method that matches the receiver.

public boolean implementedByClass(Class targetClass)

implementedByObject

Returns whether the object target implements a method that matches the receiver.

public boolean implementedByObject(Object target)

Discussion

As part of its implementation, this method uses implementedByClass.

invoke

public Object invoke(Object target, Object[] arguments)

Discussion

Invokes the method specified by the receiver on target with arguments and returns the result. If that method is void, it returns null. Note that the method may be a static or instance method.

The invoke method can’t handle arguments or return values of primitive types (such as boolean, int, or float). If the method matching the selector returns a value of a primitive type, invoke returns the value in an object of the corresponding wrapper type (such as Boolean, Integer, or Float). To pass an argument of a primitive type to invoke, use an object of the corresponding wrapper class. invoke converts the object back to the primitive type when it invokes the method.

invoke throws an exception in the following cases:

As part of its implementation, this method uses methodOnClass.

For an example, see “Using NSSelector”.

public Object invoke(Object target)

Discussion

Invokes the method specified by the selector on target with no arguments and returns the result. If that method is void, it returns null. Note that the method may be a static or instance method.

As part of its implementation, this method calls the invoke instance method which takes an array of arguments. For more information, see that method’s description.

public Object invoke(Object target, Object argument)

Discussion

Invokes the method specified by the receiver on target with one argument (argument) and returns the result. If that method is void, it returns null. Note that the method may be a static or instance method.

As part of its implementation, this method calls the invoke instance method, which takes an array of arguments. For more information, see that method’s description.

public Object invoke(Object target, Object argument1, Object argument2)

Discussion

Invokes the method specified by the receiver on target with two arguments (argument1 and argument2) and returns the result. If that method is void, it returns null. Note that the method may be a static or instance method.

As part of its implementation, this method calls the invoke instance method, which takes an array of arguments. For more information, see that method’s description.

methodOnClass

Returns the method on the class targetClass that matches the receiver. If targetClass has no method that matches the receiver, this method throws NoSuchMethodException.

public java.lang.reflect.Method methodOnClass(Class targetClass)

methodOnObject

Returns the method on the object target that matches the receiver. If target has no method that matches the receiver, this method throws NoSuchMethodException.

public java.lang.reflect.Method methodOnObject(Object target)

name

Returns the name of the method specified by the receiver.

public String name()

parameterTypes

Copies and returns the array of parameter types specified by the receiver.

public Class[] parameterTypes()

toString

Returns a string containing the receiver’s class (“NSSelector”) and the name of the method the receiver specifies.

public String toString()



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.