This article was written by me for recruiting new iOS intern students for the project team when I was still working in Didi in the middle of 2018. Some contents are no longer applicable, so it is only for reference.

Here’s my list of things you need to know to hire a credible iOS intern. Again, let me explain the situation:

  1. C. face to face D. face to face
  2. To speak fluently to the point of each question, basically can be considered to be mastered;
  3. Considering the electric face process, the psychological quality test of the electric face is very big, so, I resist the electric face process test algorithm (this is a rogue behavior) this set of questions does not involve any knowledge about the algorithm. If there is such a need, it is recommended to find a special online OJ for evaluation.

Concept part

What’s the difference between struct and class?

  • Struct cannot define functions (for procedural languages such as C)
  • Class and struct cannot be initialized with curly braces if constructors are defined. Struct can be initialized if constructors are not defined. Class only works if all member variables are public. / / but don’t have to
  • Class The default member access is private. Struct default access to your permission public. / / the key
  • Class default private; Struct default public. / / the key

Say what the following Pointers mean:

int**a: a pointer to a pointer to an integer.int *a[10] : Point to a yes10An array of Pointers, each pointing to an integer.int (*a)[10] : Point to a yes10Pointer to an array of integers.int (*a)(int) : a pointer to a function that takes an integer argument and returns an integer.Copy the code

Int and NSInterger

  • For example, in C language, the number of bytes of int and long is equal to the number of bits occupied by Pointers in the current operating system, that is to say, the length of long is always ≥ int, and we need to consider whether it is appropriate to use int or long at this time. Will overflow be caused by an error in choosing int?
  • If NSInterger is used in OC, Apple makes a judgment on its macro definition (CMD + left mouse click to see). This macro definition will automatically determine the hardware environment of the current App running, whether it is a 32-bit machine or a 64-bit machine, etc., so as to automatically return the maximum type. We don’t have to think about whether we should use int or long.

The difference between deep copy and shallow copy:

  • Shallow copy: also called pointer copy. No new memory is added, only a pointer to the original memory region is added.
  • Deep copy: Also called content copy. Copy the memory to which the pointer and pointer point, and the new pointer points to the new memory.
  • // We can extend mutable and immutable objects in OC. This problem is purely conceptual.

How are regions in memory divided?

  • Use the diagram I made earlier to illustrate:

The language of

Nil, nil, NULL, and NSNULL

  • Nil: to empty an object, to be an empty object and released completely from memory;
  • Nil: Wherever Nil is used, it can be replaced by Nil. Nil means to empty a class.
  • NULL: Indicates that a pointer is NULL. (null pointer)
  • NSNULL: Empty an OC object but want to keep its container (size).

The difference between category and extension:

  • ** Category: ** Adds new methods to known classes.
    • New methods are integrated by subclasses;
    • The new method has a higher priority than the original class, and cannot have the same name, to prevent overwriting;
    • Member variables cannot be added.
  • Extension: Add private variables and private methods to the current class, which must be implemented.

@Property keyword and related keywords understanding:

  • According to the possibility of modification, the keyword arrangement in, @Property is recommended as follows: atomicity, read-write, and memory management features;
  • Atomicity: automatic and nonautomatic. It determines whether the property is atomic, that is, in a multithreaded operation, it cannot be interrupted by another thread. If the operation using the variable cannot be completed, it will return to the state before the variable operation. But atomicity is automatic because it is a primitive operation (the primitive that guarantees the execution of the setter/getter). It degrades performance and is generally not used in iOS development but is optional in macOS development.
  • Readability: readOnly and readWrite. The default is readWrite, and the compiler helps generate serter/getter methods, whereas readOnly only helps generate getters. // readOnly modifiable variables can be modified by using KVC.
  • Memory management features:Assign, weak, strong, and unsafe_unretained.
    • Assign: generally used for value types, such as int and BOOL. (You can also modify OC objects.)
    • Weak: Used to modify reference types (weak references, which can only modify OC objects);
    • Strong: Modifies the reference type (strong reference);
    • Unsafe_unretained: used only to modify the reference type (weak reference). Different from weak, the pointer of the unsafe_unretained object is not automatically null after being destroyed. In this case, it points to a wild address.

How do YOU define an enumeration in OC?

  • There are three ways to define an enumeration in OC:

    • Because OC is COMPATIBLE with C, it can be defined using c-style enUms.
    • useNS_ENUMMacro to define;
    • useNS_OPTIONSMacro to define;
  • NS_ENUM defines the general enumeration, which can only be selected single-mode. NS_OPTIONS defines the displacement enumeration, which can be selected multi-mode. // Why is enumeration like this? Because it relates to whether or not to compile in C++ mode.

How does a Block relate to a function?

  • A Block is very similar to a function pointer, but it can access the value of an external variable outside of a function’s lexical scope.
  • Block not only realizes the function of the function, but also carries the execution environment of the function.
  • A Block is actually a pointer to a structure; (See this article.)
  • Blocks treat basic datatype variables that enter them as constants. 】
  • A Block executes a callback and does not know the object in it is appropriate to be released, so it automatically retains the object it uses internally in case the object is released before it is used.
  • Use BlockcopyModifier to modify and cannot be usedretainModify becauseretainJust conducted a callback, but the block of memory or on the stack space, the variables on the stack will be recovery system at any time, and the block memory when creating default have been allocated in the stack space, its scope is limited to its creation time, once when beyond its created outside the scope of use, causing collapse of the program, so usecopyA block may also use local variables that can only be used if it is copied into the heap space.

Why does deletegate need the weak modifier?

  • If the tableView. Deletegate is a strong reference to VC, it will lead to a circular reference, but also give us a wake-up call, when there are two objects are strong references, extremely careful!

Explain the output of this code:

  • Abbreviations:
Computer : NSObject
Mac : Computer

@implementation Mac

NSLog(@ "% @"[self class]);
NSLog(@ "% @"[super class])

@end
Copy the code
  • Both output Mac.

    • [self class] : When calling a method with self, look in the list of current class methods, or in the parent class if there is none. When you call [self class], it is converted toobjc_msgSendFunction, which is defined asid objc_msgSend(id self, SEL op, ...)The first argument is a Mac instance, but it doesn’t have one-(Class)classMethod, then go to the parent class Computer, find no, then go to the parent classNSObjectWe found it! And what we return isselfBy itself, it can be guessed that its method implementation is as follows:
    - (Class)class {
      return object_getClass(self);
    }
    Copy the code
    • [super class] : call the superclass method starting from the list of superclass methods. Converted to when [super class] is calledobjc_msgSendSuperFunction, which is defined asid objc_msgSendSuper(struct objc_super *super, SEL op, ...)And thestruct objc_superThe structure is defined as:
      struct objc_super {
        __unsafe_unretained id receiver;
        __unsafe_unretained Class super_class;
      }
      Copy the code

      So convert toobjc_msgSendSuperFunction, the first step is to constructobjc_superThe structure, the first member of the structurereceiverisselfThe second member is(id)class_getSuperclass(object_getClass("Mac")), the output result of this function is the super_class value, i.eComputerThe second step is goComputerGo to class- (Class)classAnd I didn’t find it, and I went to NSObject and I found it! Finally, useobjc_msgSend(objc_super->receiver, @selector(class))Self class = self class = self class = self classMac.

The iOS section

UITableView performance tuning methods:

  • The Cell reuse:
    • Data source method optimization: Create a static variable reuse ID, for example:static NSString *cellID = @"cellID";Static can be created only once if the number of calls is too high.
    • There are two ways for the cache pool to get a reusable Cell:dequeueReusableCellWithIdentifier:(NSString *)IDReusable Cell will be queried. If prototype Cell is registered, it can be queried. Otherwise, it is nilif(cell == nil)
    • dequeueReusableCellWithIdentifier:(NSString *)ID indexPath:(NSIndexPath *)indexPathMust be conducted by SB/class before using reusable Cell register (registerNib/registerClass), do not need to judge nil, will return to the Cell, if the buffer Cell does not exist, would use the prototype Cell to instantiate a new Cell.
  • Use only one type of Cell: reduces the amount of code and Nib files; Ensure that there is only one type of Cell. In fact, the App only has N cells after operation. However, if there are M types of cells, it may actually run at most MxN cells.
  • Hidden SubViews: Define all the different types of views and show/hide the different types of content through the cell’s enumeration of type variables and hidden, because simply showing/hiding subviews is much faster than creating them in real time in a quick swipe.
  • Calculate and cache the height of the Cell in advance. If we do not estimate row height, call firstheightForRowAtIndexPathGetting the height that each Cell is about to display is essentially determining the total tableView.contenSize before proceedingcellForRowAtIndexPath, you can build a frame model and save the cell height calculated in advance.
  • Asynchronous rendering: this is currently the most popular tableView performance tuning method, Sina Weibo is doing so, can be usedASDKThis library carries on.
  • When tableView slides, load on demand: identify tableView static or slow down after sliding, asynchronous loading, in the process of fast sliding, only load the Cell in the target orientation as needed.
  • Avoid heavy use of zooming, color gradients, transparent layers, CALayer effects, etc., and try to display the right size image resources.

Memory optimization scheme:

  • First of all, the ARC. But be careful to prevent circular references to avoid memory leaks;
  • Lazy loading. Delay the creation of an object and create it after time;
  • Reuse. Reuse of tableView, collectionView cells;
  • Use clever singletons, not all of them!

Singletons?

static User *user;
+ (User *)shareInstance {
  if (user == nil) {
    @synchronized(self) {
      / / lockuser = [User alloc] init]; }}return user;
}


+ (User *)shareInstance {
  static dispatch_onec_t onecToken;
  dispatch_onece(&onceToken, ^{
    user = [User alloc] init;
  })
  return user;
}
Copy the code

IOS remote push process?

  • To illustrate:

The concept of multithreading in iOS :(single question concept)

  • Multithreading advantage: improve the efficiency of program execution. Disadvantages: Starting threads requires certain memory controls.
  • Synchronous and asynchronous: Determines whether to start a new thread. Synchronization: The task is executed in the current thread without the ability to start a new thread. Asynchrony: Performs tasks in a new thread, with the ability to start a new thread.
  • Parallel and serial: Determine how tasks are executed. Parallel: multiple tasks concurrently (at the same time), similar to thunderbolt multi-task download at the same time; Serial: After one task is executed, the next task is executed, similar to downloading one task at a time.
  • Important: It must be clear that there is only one main thread in iOS, the UI thread, and time-consuming tasks should not be executed on the main thread, otherwise it will cause lag.

Summary: Again, in the actual interview process, this set of questions can only be used for reference, and there will be questioning and waiting process in the interview process, so the best interview time is the best within 30 minutes, too short? Remember! This move is an intern, and this is electric face!! Don’t learn what big company grumpy, an intern’s telephone interview you have to do an hour or even two hours, there is no need. If it’s face to face ask for an hour or two, but the point is this is electricity! Don’t use this type of interview as the ultimate measure of a person’s ability to do the job, unless you’re sure that you’ll be doing the same thing in the future.

Also the content of this set of items is not recommended as a side, one side should be as to understand the status of the candidate’s career, the basic level (also is the logical ability), recommend this set of items as a second interview, include the basic knowledge of iOS development foundation, and can grasp the good time in 30 minutes, three sides should focus on the project actual situation, And better face to face. All around HR face, try not to have 5, too afflictive. Actually, three sides are the best.

Remember! Don’t repeat the topic, but draw other questions by analogy.