Interview Questions - OC Basics

1. What is the difference between #import and #include, what about @class, what is the difference between #import<> and #import””?

#import is the keyword of Objective-C import header file,
#include is the keyword of C/C++ import header file,
using #import header file will automatically import only once, and will not import repeatedly, which is equivalent to #include and #pragma once ;
@class tells the compiler to check the implementation file of a certain class when it is executed, which can solve the problem of mutual inclusion and circular reference of header files; #import<> is used to
include system header files, #import "" is used to include user header files.
 

2. What is Category? The role of category (category)?

Category is a category, and the method of rewriting a class with Category is only valid for this Category, and will not affect the relationship between other classes and the original class.

  1. Create a forward reference to a private method
  2. Realization of Distributed Classes
  3. Implement informal agreements

3. Can Object-c classes have multiple inheritance? Can multiple interfaces be implemented? What is the difference between inheritance and class in implementation

oc cannot have multiple inheritance, and can implement multiple interfaces with Protocol proxy

the difference:

  1. Inheritance is ":" plus the name of the parent class, and the category is the name of the declared category and the class it is added to
  2. The same name as the method in the class, the method in the class has higher priority, and the method of the class itself will have no effect
  3. A category is a new extension to a class that cannot modify a class. Inheritance not only adds new extensions but also modifies methods in deleted classes;
  4. A category is an extension of a method, and inheritance can derive new attributes and new member variables
     

4. What does OC dynamic runtime language mean?

  1. Different objects can receive the same message, and can do different implementations
  2. The OC language defers the determination of data types from compile time to runtime
  3. runtime call
<obj/runtime.h>
obj_sendMsg(id reciver, selector);
[obj method];

What are the characteristics of the object declared by id

The object declared by id has runtime characteristics, that is, it can point to any type of objcetive-c object;

5. How are methods different from selectors?

  1. The method consists of two parts: declaration and implementation.
  2. The selector is the name of the method
    performselector:(SEL)

Guess you like

Origin blog.csdn.net/guoxulieying/article/details/131960811