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

What's the difference between marking a method as @o...

Câu trả lời

The main difference between marking a method as @objc vs dynamic in Swift is:

  • @objc exposes the method to the Objective-C runtime, allowing it to be called from Objective-C code[1][5]. This is required for features like key-value observing to work correctly[1].

  • dynamic tells the Swift compiler to always use Objective-C dynamic dispatch for the method, rather than static or virtual dispatch[1][2]. This is necessary if you plan to modify the method implementation at runtime using the Objective-C runtime[2].

In Swift 4 and later, dynamic no longer implies @objc - you must explicitly use @objc dynamic to get both Objective-C visibility and dynamic dispatch[2][3].

You would use @objc when:

  • Interacting with Objective-C frameworks and APIs that require Objective-C visibility[5]
  • Using Objective-C features like selectors...
expert

expert

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

middle

What is difference between these three classes [NSManagedObject, NSManagedObjectContext,
NSManagedObjectModel] of CoreData?

middle

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

entry

Name four important data types found in Objective-C

Bình luận

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

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