IOS captures calls to unknown methods to avoid throwing exceptions.

Source: Internet
Author: User

The NSObject object is the root class in Objecitve-C. It has the following two methods. When the method that calls NSObject and its subclass does not exist, it encapsulates this call into the NSInvocation * type and tries to pass it to forwardInvocation: method. If the object called by the original method loads forwardInvocation: method, forwardInvocation: method will be called.

ForwardingTargetForSelector: the real purpose of this function. From the descriptions on the official website, we still do not fully understand the available scenarios, but the latter method was used for reflection processing, see O-R Mapping for json data sources implemented by iOS ".

ForwardingTargetForSelector:

Returns the object to which an unknown message should first be redirected.
Returns the object to which unrecognized messages shoshould first be directed.

-(Id) forwardingTargetForSelector :( SEL) aSelectorforwardInvocation:

It is overloaded by sub-classes and 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];    }}









Related Article

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.