IOS captures unknown method calls, avoids throwing exceptions
The beautiful Life of the Sun Vulcan (http://blog.csdn.net/opengl_es)
This article follows "Attribution-non-commercial use-consistent" authoring public agreement
Reprint Please keep this sentence: Sun Vulcan's Beautiful Life-this blog focuses on Agile development and mobile and IoT device research: IOS, Android, HTML5, Arduino, Pcduino , Otherwise, the article from this blog refused to reprint or re-reproduced, thank you for your cooperation.
The NSObject object is the root class in Objecitve-c, which has the following two methods that, when a method that calls NSObject and its subclasses does not exist, encapsulates the call as a nsinvocation * type, attempting to pass it to the Forwardinvocation: method, if the object that was called by the original method overloads the Forwardinvocation: method,forwardinvocation: The method is called.
Forwardingtargetforselector: The real use, from the official website of the description, or not fully understand its available scenes, but the latter method in the reflection processing when used, see " O-r Mapping for the JSON data source implemented by IOS ".
Forwardingtargetforselector:
Returns the object to which the unknown message should first be turned.
Returns the object to which unrecognized messages should first is directed.
-(ID) Forwardingtargetforselector: (SEL)AselectorForwardinvocation:
A subclass overload that is used to forward messages to other objects.
Overridden by subclasses to forward messages to other objects.
-(void) Forwardinvocation: (Nsinvocation *)aninvocation
-(void) Forwardinvocation: (nsinvocation *) invocation { SEL orignalselector = [invocation selector]; if ([friend Respondstoselector:orignalselector]) { [invocation invokewithtarget:friend]; } else { [super forwardinvocation:invocation];} }