iOS Development Init method parsing

Source: Internet
Author: User
The Init method of the parent class must be called by the custom Init method.     Generally:-(ID) init{[super Init]; xxx = xxx;} Typically, this pattern can satisfy the overwhelming majority of requirements, but in a few cases, special handling is required. 1, for optimization reasons, the Init method frees the object that has already been allocated memory, and then creates another new object and returns it. The 2,init method has an error during execution, so the object is freed and nil is returned. For 1, Apple's approach is to give the parent Init method The return value to self, for 2, Apple's official website is to detect whether the parent class returns the object is nil, nil does not need to continue.     So, Apple's recommended init customization method is:-(id) init{self = [super init];     if (self) {xxx = xxx; } return self;} In init, you can assign values directly, or you can use the access method. People who prefer direct assignment think that an object can be initialized only after the Init has been executed. People who prefer to use access methods think that the access method can do other things besides assigning values to instance variables. You can use the access method whenever you set an instance variable.

iOS Development Init method parsing

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.