Oc-objection one of the learning notes: a simple start

Source: Internet
Author: User

Objection The reference problem of the unified management object, I think this is the meaning of this technology.

Don't talk nonsense, let's go straight to the steps:

1: protocol

It is our consciousness to know that everything revolves around agreements.

The following protocol is a view of the Protocol, the Protocol is simply no longer easy.

It does not expose any variables and interfaces, just to refer to the view corresponding to the protocol.



I tend to write a protocol separately into a file.

Then, all the protocols are referenced in the same file.

Finally, put the file in the PCH as a global file.

The principle that follows is that the protocol is shared.

2: Class implementation for protocol correspondence

In this example is a view, of course, to follow the protocol.

3: Class for registration protocol

Objection since the object is to solve the reference problem, then through the protocol, it wants to register the object in.

How to do it?

3.1:objection is implemented through Jsobjectionmodule.

@interface searchviewctrlmodule:jsobjectionmodule @end  @implementation searchviewctrlmodule-(void) Configure {     

3.2: Add into objection:

Jsobjectioninjector *injector = [Jsobjection defaultinjector];injector = injector? : [Jsobjection createinjector];injector = [injector Withmodule:[[searchviewctrlmodule alloc] init]]; [Jsobjection Setdefaultinjector:injector];

  

4: Use

Jsobjectioninjector *injector = [Jsobjection defaultinjector]; Uiviewcontroller <SearchViewCtrlProtocol> *VC = [Injector getObject: @protocol (Searchviewctrlprotocol)];

Oc-objection one of the learning notes: a simple start

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.