- forwardingTargetForSelector:
The invocation to forward. この呼び出しを転送します。
Availability
Technology
- (void)forwardInvocation:(NSInvocation
*)anInvocation;
anInvocation
The invocation to forward. この呼び出しを転送します。
When an object is sent a message for which it has no corresponding method, the runtime system gives the receiver an opportunity to delegate the message to another receiver.
あるオブジェクトが、それが対応するメソッドを持たないメッセージを送られる場合、ランタイムシステムは、メッセージを別のレシーバに委任する機会をそのレシーバに与えます。
It delegates the message by creating an NSInvocation
object representing the message and sending the receiver a forward
message containing this NSInvocation
object as the argument. The receiver’s forward
method can then choose to forward the message to another object. (If that object can’t respond to the message either, it too will be given a chance to forward it.)
(そのオブジェクトもまたメッセージに応答出来ないならば、それもまたそれを転送する機会を与えられます。)
The forward
message thus allows an object to establish relationships with other objects that will, for certain messages, act on its behalf. The forwarding object is, in a sense, able to “inherit” some of the characteristics of the object it forwards the message to.
転送先のオブジェクトは、ある意味では、メッセージの転送元のオブジェクトのいくつかの特徴を「継承する」ことができます。
Important 重要
To respond to methods that your object does not itself recognize, you must override method
in addition to forward
. The mechanism for forwarding messages uses information obtained from method
to create the NSInvocation
object to be forwarded. Your overriding method must provide an appropriate method signature for the given selector, either by pre formulating one or by asking another object for one.
あなたのオーバーライドメソッドは、指定されたセレクタに対して適切なメソッドシグネチャを提供しなければなりません、あらかじめ考案するものによって、または別のオブジェクトにそれを要求することによってのどちらかで。
An implementation of the forward
method has two tasks:
To locate an object that can respond to the message encoded in an
. This object need not be the same for all messages.
このオブジェクトは、全てのメッセージに対して同じものである必要はありません。
To send the message to that object using an
. an
will hold the result, and the runtime system will extract and deliver this result to the original sender.
In the simple case, in which an object forwards messages to just one destination (such as the hypothetical friend
instance variable in the example below), a forward
method could be as simple as this:
The message that’s forwarded must have a fixed number of arguments; variable numbers of arguments (in the style of printf()
) are not supported.
The return value of the forwarded message is returned to the original sender.
転送されたメッセージの戻り値は、元々の送り手(センダー)に返されます。
All types of return values can be delivered to the sender: id
types, structures, double-precision floating-point numbers.
Implementations of the forward
method can do more than just forward messages. forward
can, for example, be used to consolidate code that responds to a variety of different messages, thus avoiding the necessity of having to write a separate method for each selector. A forward
method might also involve several other objects in the response to a given message, rather than forward it to just one.
NSObject
’s implementation of forward
simply invokes the does
method; it doesn’t forward any messages. Thus, if you choose not to implement forward
, sending unrecognized messages to objects will raise exceptions.
- forwardingTargetForSelector: