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

Which is the best of GCD, NSThread or NSOperationQueue ?

senior

What's the difference between using a delegate and notification?

junior

What are blocks and how are they used?

Bình luận

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

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