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

Why delegate is...

Câu trả lời

Here is an explanation for why delegates are never retained in Objective-C:

Delegate Pattern in Objective-C

In Objective-C, the delegate pattern is a common design pattern used to implement one-to-one communication between objects. A delegate is an object that acts on behalf of another object, handling tasks and responding to messages on its behalf.

Weak References and Delegates

When an object sets another object as its delegate, it typically uses a weak reference to the delegate. This means that the delegate is not retained or owned by the object that sets it. The reason for this is to avoid a strong reference cycle, which can lead to memory leaks.

Avoiding Strong Reference Cycles

If an object retained its delegate, and the delegate also had a strong reference back to the object, it would create a strong reference cycle. This means that both objects would hold strong references to each other, preventing them from being deallocated even when no other part ...

senior

senior

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

middle

What is Key-Value-Coding and Key-Value-Observing in Objective-C?

senior

What is @autoreleasepool ?

expert

What's the difference between marking a method as @objc vs dynamic , when would you do one vs the
other?

Bình luận

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

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