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

What are some limitations and problems you can face with categories?

Câu trả lời

Here are some key limitations and problems that can arise when using categories in Objective-C:

Naming Conflicts

Categories allow you to add methods to existing classes, even classes you don't have the source code for. However, this also means you can accidentally override existing methods in the class if you use the same method name. This can lead to unexpected behavior and bugs.

Lack of Instance Variables

Categories cannot add instance variables to a class. If you need to store state related to the methods you add in a category, you'll need to use associated objects, which can be less efficient and harder to manage.

Compile-Time Checking

Methods added via categories are not checked at compile-time. If you misspell a method name or pass the wrong arguments, you won't get a compile error. The issues will only surface at runtime.

Method Dispatch Order

When a class has multiple categories that implemen...

middle

middle

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

expert

What sending a message to nil means and how is it actually useful?

senior

What are the differences between implementing a @property with @dynamic or @synthesize ?

junior

What is the reuseIdentifier used for?

Bình luận

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

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