IOS captures unknown method calls, avoids throwing exceptions

Source: Internet
Author: User

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];}    }









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.