For non professional class IOS development, an interview question (with answers)

Time:2020-11-22

After experiencing the outbreak period in the past few years, the IOS industry has come to a relatively calm period. It is a stage of good money expelling bad money, eliminating the false and retaining the true. Only with continuous focus and dedication, can we stand out in the fierce competition and become a strong one. As Dickens said,“It’s the worst of times and the best of times.”

For these interview questions, don’t memorize them by rote. We should draw inferences from one instance and deeply understand the implementation mechanism (this is one of the differences between the professional class and the non professional class). The answers to the interview questions are for reference only. Please correct them if you have any mistakes.

If you let you implement the weak attribute, how to achieve it?

runtimeThe registered classes will be arranged, and theweakThe decorated object will be placed in ahashIn the table. The memory address of the object pointed to by weak is used as the key. When the reference count of this object is 0, thedeallocIfweakIf the memory address of the object pointed to is a, then search the weak table with a as the key to find all the objects with a as the keyweakObject is set tonil

If you are asked to implement atomic properties, how to implement them?

- (void)setCurrentImage:(UIImage *)currentImage
{
    @synchronized(self) {
        if (_currentImage != currentImage) {
            [_currentImage release];
            _currentImage = [currentImage retain];
            // do something
        }
    }
}
- (UIImage *)currentImage
{
    @synchronized(self) {
        return _currentImage;
    }
}

Why does KVO create a subclass to implement?

Runtime dynamically generates an nskvonotification_ Class subclass, which can be added dynamicallywillChangeValueForKeyanddidChangeValueForKeyObserve the changes in all attributes

The composition of class structure, what does isa pointer point to? (metaclass and root metaclass should also be mentioned here)

Isa: it is a pointer of class type. Each instance object has an ISA pointer, which points to the class of the object, and there is also an ISA pointer in the class, which points to the metaclass. Metaclass holds a list of class methods. When a class method is called, it will first find the implementation of the class method from itself. If not, the metaclass will look for the method from its parent class. Also note that metaclass is also a class, it is also an object. Metaclass also has isa pointer. Its isa pointer eventually points to a root metaclass. The ISA pointer of the root metaclass points to itself, forming a closed inner loop.

 
For non professional class IOS development, an interview question (with answers)
image

How many event sources does runloop have? How many modes are there?

The purpose of the runloop is to:

Basic function: keep the program running continuously and ensure that the program does not exit
 2. Handle various events in app (such as touch event, timer event, selector event)
 3. Save CPU resources and improve program performance: when you do something, you should rest
  • Event source: input source and timing source
  • Patterns: there are four modes. The first is the default mode: the mode used by general method calls. The second is tracking mode: it is used for Scrollview to track touch and slide, so that it is not affected by other modes and can coexist. The third is the running cycle mode that is opened for the first time when the program starts. The fourth kind of words has not been heard in general development. I haven’t studied it. In fact, there is a pattern of occupancy. But it’s not very useful.

What is the data structure of the method list?

struct objc_method_list
{
  struct objc_ method_ list*  method_ Next; / * this variable is used to link to another separate method list*/
  int            method_ The number of methods defined in the count; / * structure*/
  struct objc_ method method_ List [1]; / * variable length structure*/
};

How is classification realized? Why does it override the original method?

Because the operation of adding a classification method to a class is completed when the runtime system loads the classification, the runtime system will add each method implemented in the classification into the method list of the class

  • Instance methods, protocols, and properties of category are added to the class
  • The class methods and protocols of category are added to the metaclass of the class

The method of category is put in front of the new method list, while the method of the original class is put after the new method list, so the method of category will “override” the method with the same name of the original class.

I hope that the experience I have shared can be helpful to you, and I hope you can finally enter the enterprise you like.

Networking

Finally, I recommend a seniorIOS communication group: 1001906160, it’s important to have a common circle and get to know people! There are IOS development, full stack development, welcome to settle in, common progress! Several hundred free papers and answers are provided for free

Recommended Today

Explain module, import and export in JavaScript

Author: Tania rascia Crazy technology house Original text:https://www.taniarascia.com/j… In the era of the Internet, websites are mainly developed with HTML and CSS. If you load JavaScript into a page, it usually provides effects and interactions in the form of small fragments. Generally, all JavaScript code is written in a file and loaded into a filescriptTag. […]