Câu hỏi phỏng vấn Objective-C
Câu hỏi

What's the difference between the atomic and nonatomic attributes?

Câu trả lời

Here is an explanation of the difference between the atomic and nonatomic attributes in Objective-C:

Atomic Attribute

  • The atomic attribute is the default behavior for properties in Objective-C.
  • When a property is declared as atomic, the compiler generates accessor methods (getter and setter) that are thread-safe.
  • This means that if multiple threads access the property simultaneously, the property's value will remain consistent and valid.
  • The atomic implementation uses locks or semaphores to ensure thread safety.
  • However, atomic properties can have a slight performance impact due to the overhead of acquiring and releasing locks.

Nonatomic Attribute

  • The nonatomic attribute is used to explicitly declare that a property is not thread-safe.
  • When a property is declared ...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

What is Dynamic Dispatch and how does it work in Objective-C?

middle

When would you use Categories over Inheritance and vice versa?

senior

What is the difference between ARC (automatic reference counting) and GC (garbage collection)?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào