52 Essentials of iOS Development summary of two

Source: Internet
Author: User

6, you can use the attribute @property syntax to define the data encapsulated in the object.

Specify the correct semantics required for data storage by "traits".

When setting an instance variable corresponding to a property, be sure to follow the semantics declared by that property.

You should use the Nonatomic property when developing an iOS program because the atomic property can severely affect performance.

7. When reading data inside an object, it should be read directly through the instance variable, and when writing the data, it should be written by property.

In the initialization method and the Dealloc method, the data should always be read and written directly through the instance variable.

Sometimes a piece of data is configured using lazy initialization techniques, in which case the data needs to be read through the property.

8, to detect the equality of objects, please provide "isequal:" and the hash method.

The same object must have the same hash code, but the same object is not necessarily the same as the two hash codes.

Do not blindly detect each property individually, but should be based on the specific needs of the test plan.

When you write a hash method, you should use an algorithm that is fast and has a low probability of collision with the hash code.

9, the class family mode can hide the implementation details behind a set of simple public interfaces.

Class families are often used in system frameworks.

Be careful when inheriting subclasses from the common abstract base class of a class family, if you have a development document, you should read it first.

10, through the Objc_setassociatedobject "Association object" mechanism to connect two objects together.

When defining an association object, you can specify memory management semantics to mimic the "owning relationship" and "non-owning relationship" used when defining attributes.

Associate objects should be used only when other practices are not available, because this practice often introduces bugs that are difficult to find.

52 Essentials of iOS Development summary of two

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.