iOS cable Cheng

Source: Internet
Author: User

Locking

@synchronized (self) {

At the same time, only one thread can execute, but very expensive source

}//Unlock

About the lock, here's a thing. About this syntax: @property. Each time we define a property, we will be the first to write the nonatomic, which is why? Please see the following explanation:

The difference between nonatomic and atomic in @property:

All know, these two keywords represent the same thing, but the meaning of the representative is different. is thread-related.

Nonatomic represents: Threads are unsafe.

Atomic stands for: threads are safe.

So, here's the question. What is the concrete manifestation of security and insecurity? is actually whether to give this attribute setter method whether lock.

Nonatomic stands for: there is no lock on the setter method for this property, so it is unsafe.

Atomic represents: The setter method of this property is locked, so it is safe.

So, here comes the question again. Why should we recommend using Nonatomic in our iOS development?

This problem should start with the depletion of resources. In iOS development, the invocation of setter methods is very frequent. It is very resource-intensive to lock the setter method. So on mobile devices, use nonatomic as much as possible. In MAC development, it is usually the use of atomic. If you care about security issues, there is no problem with using atomic.

iOS cable Cheng

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.