IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview



I will review the corresponding contents one by one. At the same time, I will add the missing knowledge points to the text, record my notes and share them. You can collect what you like. Let’s work together.

The following is the IOS technology points + interview question classification collected and summarized by Xiaobian; See if you can do it?

Key Summary – several categories:

  • Underlying principles of IOS
  • Performance optimization and architecture
  • Multithreading, network
  • Data structure algorithm

Underlying principle of IOS (must ask): it is a necessary ability for IOS development, and it is also one of the ways for large factories to interview and quickly screen talents.

The interviewer asked:

1、 Performance optimization point
2、 How to solve the project difficulties
3、 The project process includes quality control review and review code
4、 How does HTTP send data tcp3 handshake
5、 Smart pointer, what’s the defect of smart pointer
6、 Unclean release (for example, a = B, B = a)

51. The difference between array and linked list
-Arrays give contiguous space in memory
-The memory address of a linked list can be discontinuous. The node of each linked list includes the information of the original memory and the next node (one for one-way and two for two-way linked lists)

-Advantages: easy to use, higher query efficiency than linked list, and memory is a continuous area 
-Disadvantages: fixed size, not suitable for dynamic storage and inconvenient for dynamic addition

 Linked list: 
-Advantages: dynamic addition and deletion, variable size   
-Disadvantages: it can only be accessed through sequential pointers, and the query efficiency is low
53. Talk about your understanding of compilation and linking

Electronic IOS interview questions + Answers:

Because there are too many answers to the article, I made a PDF document. Because developer can’t upload files, because the article is limited, I need these documents,

clickTencent documentsTake it yourself

Screenshot of display part: ↓↓↓↓↓

IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview

IOS interview documents
54. Use of leak tool
55. Application startup process and startup optimization
-How do I load all dependent mach-o files when the application starts?
-Please list the time-consuming factors you know before the main() function

There are two types of APP startup:
-Cold launch: start the app from scratch
-Warm launch: the app is already in memory and survives in the background. Click the icon again to start the app

The optimization of start-up time is mainly for cold start
1. By adding environment variables, you can print the startup time analysis of the app (see the figure below for details)
- DYLD_ PRINT_ STATISTICS_ Details (more detailed than the previous one)
-Generally, it is normal within 400ms

Print results:
Total pre main time: 238.05 milliseconds (100.0%) // main total time before function call (pre main)
         Dylib loading time: 249.65 milliseconds (104.8%) // dynamic library time consuming 
        rebase/binding time: 126687488.8 seconds (18128259.6%) 
            Objc setup time: 10.67 milliseconds (4.4%) // OC structure preparation takes time 
           Initializer time: 52.83 milliseconds (22.1%) // initialization time 
           Slowest initializers: // slow loading 
             libSystem.B.dylib :   6.63 milliseconds (2.7%)
   libBacktraceRecording.dylib :   6.61 milliseconds (2.7%)
    libMainThreadChecker.dylib :  31.82 milliseconds (13.3%)

2. Cold start can be summarized into three stages
- dyld
- runtime
- main

3. Dynamic D (dynamic link editor), Apple's dynamic connector, can load mach-o (executable files, dynamic libraries, etc.)
-Load the app executable, and recursively load all dependent dynamic libraries
-When dyld finishes loading the executable file and dynamic library, it will notify the runtime to proceed with the next step

4. What the runtime does
-Call map_ Calling call_ in images function load_ Methods, call the + load method of all classes and categories
-Initialize various objc structures (register objc classes, initialize class objects, etc.)
-Call C + + static initializer and__ attribure__ ((constructor)) modified function (there are specific applications in jsonkit)
-So far, all symbols (class, protocol, selector, imp...) in the executable file and dynamic library have been successfully loaded into memory according to the format and managed by the runtime

5. Summary
-The startup of app is dominated by DyLB, which loads executable files into memory and all dependent dynamic libraries
-The runtime is responsible for loading the structure defined by objc
-After all initialization work, dyld will call the main function
-Next is the applicationmain function, appdelegate's application: didfinishlaunchingwithoptions: method

6. Optimize according to different stages
-Reduce dynamic libraries and merge some dynamic libraries (clean up unnecessary dynamic libraries regularly)
-Reduce the number of objc classes and classifications and the number of selectors (regularly clean up unnecessary classes and classifications)
-Reduce C + + fictional functions
-Swift tries to use struct

-Use the + initialize method and dispatch_ Once replaces all__ attribute__ ((constructor)), C + + static constructor, objc's + load method

-Without affecting the user experience, delay some operations as much as possible, not all in the finishlaunching method
-Load on demand
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview

DYLD_ PRINT_ Statistics is set to 1
56. Package volume optimization
Installation package downsizing (IPA): resource files, executable files

Resource files (pictures, audio, video, etc.)
-Lossless compression (using tools)
-Remove unused resources( )

Executable slimming:
-Compiler optimization (Xcode related configuration)
-Using appcode( )Detect unused codes: menu bar - > code - > inspect code
-Generate linkmap to view the specific composition of the executable file
-Linkmap files can be parsed with the help of third-party tools:
57. Project optimization and performance optimization
Starting speed:
-The less you do during startup, the better (merge as many interfaces as possible)
-Operations that do not consume time on the UI thread (data processing is performed in the sub thread, and the main thread is notified to refresh the program after processing)
-Start the background task at an appropriate time (for example, when the user guides the program, you can start preparing the loaded data)
-Minimize package size
-Auxiliary tools (Youmeng, Tingyun, Flurry)

Page browsing speed
-JSON processing (nsjsonserialization, jsonkit, sbjson provided with IOS)
-Paging of data (if there is a lot of back-end data, it should be returned by paging, such as Netease News or microblog records)
-Data compression (big data can also be compressed and returned to reduce traffic and speed up response)
-Content cache (for example, the latest news list of Netease News should be cached locally and loaded locally. It can be cached to memory or database, depending on the situation)
-Delay loading tabs (for example, the app has five tabs. The first tab to be displayed can be loaded first, and the others can be loaded when displaying. Load as needed
-Optimization of algorithm (optimization of core algorithm, for example, some apps have a contact name sorted by the first letter of Chinese Pinyin)

Operation fluency optimization
-Tableview optimization (loading optimization of tableview cell)
-Viewcontroller loading optimization (jump between different views, data can be prepared in advance)
58. Tell me about yourself
-Your technical highlights and difficulties in the project
-Your development direction (Career Planning)
-Your strengths, your weaknesses
59. Talk about componentization. How do you decouple components
Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
60. Static library and dynamic library
1. What is a library?
-Sharing code, realizing code reuse, is generally divided into static library and dynamic library.

2. The difference between static library and dynamic library
Static libraries (. A and. Framework styles):
-When linking, the full copy is made to the executable file, and multiple copies are used for multiple times, resulting in redundancy and making the package larger
-However, the code loading speed is fast and the execution speed is slightly faster than that of the dynamic library

Dynamic library: (. Dylib and. Framework)
-The link is not copied. When the program is running, it is added to the memory by the system for system call. The system is added once and used many times to save memory.

3. Why is the framework both static and dynamic?
-The system framework is dynamic and self created is static.

4. What is the difference between. A and. Framework?
-. A is a simple binary file, which needs the cooperation of. H file and cannot be used directly
-. framework is a binary file + resource file, which can be used directly Framework =. A +. H + sorrcefile (resource file)

13、 OC object related

61. Understanding of the source code of class in OC? What is the understanding of cache? Talk about nscache cache policy
struct objc_class {
    Class _Nonnull isa  OBJC_ISA_AVAILABILITY;

#if !__OBJC2__
    Class _Nullable super_class                              OBJC2_UNAVAILABLE;
    const char * _Nonnull name                               OBJC2_UNAVAILABLE;
    long version                                             OBJC2_UNAVAILABLE;
    long info                                                OBJC2_UNAVAILABLE;
    long instance_size                                       OBJC2_UNAVAILABLE;
    struct objc_ivar_list * _Nullable ivars                  OBJC2_UNAVAILABLE;
    struct objc_method_list * _Nullable * _Nullable methodLists                    OBJC2_UNAVAILABLE;
    struct objc_cache * _Nonnull cache                       OBJC2_UNAVAILABLE;
    struct objc_protocol_list * _Nullable protocols          OBJC2_UNAVAILABLE;

/* Use `Class` instead of `struct objc_class *` */

62. Can attributes be added to the protocol
-The protocol of OC language supports declarative attributes
-However, declaring attributes in the protocol is actually the same as defining methods in it. It only declares getter and setter methods without specific implementation
63. OC inline function
-Override macro

Inline functions are different from macros
-Solve the problem of function call efficiency
-Calls between functions are calls between memory addresses. After the function call is completed, the address of the original function execution will be returned.
-Function calls have time overhead, and inline functions are designed to solve this problem

Advantages of inline over macros
-It avoids the disadvantage of macros: precompiling is required. Because inline functions are also functions, precompiling is not required
-When calling an inline function, the compiler will first check the type of its parameters to ensure that the call is correct. It eliminates its hidden dangers and limitations.
-You can use protected and private members of your class

Advantages of inline over functions
-The inline function avoids the disadvantage of ordinary functions that call must be called during assembly: it cancels the function parameter stack, reduces the calling overhead and improves efficiency. Therefore, the execution speed is faster than that of ordinary functions
-It integrates the advantages of macros and directly replaces them with code (like macros)
64. What is the difference between ID and nsobject and instancetype?
-Both ID and instancetype can be used as the return value of the method.

-The return value of ID type cannot judge the real type of the object at compile time, that is, the non associated return type
-The return value of instancetype type can judge the real type of the object at compile time, that is, the associated return type.

-ID can be used to define variables, as return values, and as formal parameters
-Instancetype can only be used as a return value.

Non associated return type, associated return type
Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
65. What is the function of method signature?
Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
66. What is the difference between nil, nil, null and nsnull?
-Nil: null pointer to an object    
-Nil: null pointer to a class,   
-Null: null pointer to other types (such as basic type and C type), which is used to assign null value to non object pointer
-Nsnull: an object representing a null value in a collection object

Nsnull is a class in Objective-C. nsnull has + (nsnull *) null; Singleton method. It is mostly used for objects with empty value in the set (nsarray, nsdictionary)

NSArray *array = [NSArray arrayWithObjects: [[NSObject alloc] init], [NSNull null], @"aaa", nil, [[NSObject alloc] init], [[NSObject alloc] init], nil];
NSLog(@"%ld", array.count);//  Output 3, nsarray ends with nil
67. Underlying implementation principle of nsdictionary
-In OC, nsdictionary uses hash table to map and store key and value.

Brief introduction to hash table stored procedure:
-Calculate its hash value according to the key value;
-Assuming that the number of boxes is n, the key value pair should be placed in the (h%n) box.
-If there are already key value pairs in the box, the open addressing method or zipper method is used to solve the conflict. When using zipper method to solve hash conflict, each box is actually a linked list, and all key value pairs belonging to the same box will be arranged in the linked list.
68. How to find the property of the parent class?
-Property in subclass_ list、method_ list、ivar_ List does not contain a parent class
-Of subclass objects_ Impl contains the name of the parent class

Answer from the above points
Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
69, + load and + initialize
common ground:
-Method is executed only once
-These two methods are called automatically before the class is used

-Different execution timing ()

-Load method: if the class itself is not defined, the load method of its parent class will not be called;
-Initialize method: if the class itself is not defined, the initialize method of its parent class will be called;

Preconditions for implementation:
-Load is executed as long as the file where the class is located is referenced; 
-If the class is not referenced into the project, there will be no load execution; 
-Initialize needs the first method of the class or its subclass to be called before it is executed, and it is executed before the first method is executed; 
-Even if the class file is referenced into the project but not used, initialize will not call for execution;
70. How to implement multiple inheritance in IOS? Write the code
-Use protocol combination
- NSProxy

Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
71. Difference between class and structure
-Structures can only encapsulate data, while classes can also encapsulate behavior
-Assignment: the structure is a copy, and the objects are addresses
-Structure variables are allocated in stack space (if it is a local variable), while objects are allocated in heap space
72. How to solve the crash and crash the underlying code
Nssetuncaughtexceptionhandler can count flashbacks
Todo (to be filled); ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️ ⌛ ️
73. Properties, member variables, set and get methods
-Can the property exist simultaneously with the set method and the get method? If not, please explain why?
In other words: why can't you access the underscore property when you rewrite the set and get methods of the property at the same time in IOS?

-The setter method and getter method of the property cannot be overridden at the same time,
-Because once you override the two methods at the same time, the system will not generate the member variable for you

@synthesize authType = _authType;
-This means that the setter and getter methods of the property are applied to this variable.
74. ISA is related to superclass
1. Where does the ISA pointer of the object point? What about the superclass pointer? ( ⚠️ Figure - Summary)
-Isa of instance points to class
-The ISA of class points to meta class
-Isa of meta class points to meta class of base class

-The superclass of class points to the class of the parent class (if there is no parent class, the superclass pointer is nil)
-The superclass of meta class points to the meta class of the parent class
-  ⚠️ The superclass of the meta class of the base class points to the class of the base class

2. Method call lookup( ⚠ ️ ⚠ ️ ⚠ (Figure - trace of instance call object; figure - trace of class method call)
-Call of object method: find the class through isa of instance, and finally find the implementation of object method for calling
-Calling of class methods: when calling class methods, find meta class through isa of class, and finally find the implementation of class methods for calling

3. Superclass pointer to class object
Student : Person : NSObject

When the instance object of student wants to call the method of personal object:
-First find the student's class through ISA, then find the person's class through superclass, and finally find the implementation of the object method to call

4. Superclass pointer to meta class object
When student's class wants to call person's class method
-First find the student's meta class through ISA, then find the person's meta class through superclass, and finally find the implementation of the class method to call
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
IOS development job hopping into Xiaomi, stroked the knowledge points of IOS interview
75. Where is OC information stored?
-Object methods, attributes, member variables, and protocol information are stored in the class object
-Class method, stored in the meta class object
-The specific value of the member variable is stored in the instance object

76. Structure of class and meta class

struct objc_class : objc_object {
    Class ISA;
    Class superclass;
    cache_ t cache;             //  Method cache
    class_ data_ bits_ t bits;    //  Used to obtain specific class information


struct class_rw_t {
    uint32_t flags;
    uint32_t version;
    const class_ro_t *ro;        // 
    method_ array_ t methods;      //  Method list
    property_ array_ t properties; //  Attribute list
    protocol_ array_ t protocols;  //  Protocol list
    Class firstSubclass;
    Class nextSiblingClass;
    char *demangledName;

struct class_ro_t {
    uint32_t flags;
    uint32_t instanceStart;
    uint32_t instanceSize;
#ifdef __LP64__
    uint32_t reserved;

    const uint8_t * ivarLayout;
    const char * name; //  Class name
    method_list_t * baseMethodList;
    protocol_list_t * baseProtocols;
    const ivar_ list_ t * ivars; //  Member variable list

    const uint8_t * weakIvarLayout;
    property_list_t *baseProperties;

Recommended reading: IOS popular interview technology collection

Recommended Today

Seven solutions for distributed transactions

1、 What is distributed transaction Distributed transaction means that transaction participants, transaction supporting servers, resource servers and transaction managers are located on different nodes of different distributed systems. A large operation is completed by more than n small operations. These small operations are distributed on different services. For these operations, either all of them are […]