Summary of iOS interview in February 2018

Summary of iOS interview in February 2018

In mid-to-late February this year, I changed jobs for personal reasons. During this period, I interviewed 4 or 5 companies, most of which were round D or listed companies. I also saw some of my shortcomings from their interviews and written tests, so I want to write it down and share it with you. It would be great if it can help students who are currently interviewing. From the interview questions, you can actually see the development of some industries and the overall talent demand.

1. Written test questions

There are basically one or two basic questions in the written test, such as the reuse mechanism of UITableView, the basic principle of ARC, how to avoid retain cycle, talk about the understanding of MVC, and the memory management mechanism of iOS. Everyone should be very clear about these. There are several types of written test content, including multiple-choice questions, essay questions, and the more difficult ones are multiple-choice questions. I interviewed a company that gave 10 multiple-choice questions. It was not okay to choose too many, too few, or wrong choices. I didn’t feel very good after finishing them. Some questions just asked which ones were correct, and then ABCD gave 4 different concepts in sequence. This kind of question is equivalent to testing 4 points. In short, don’t panic when you encounter such "disgusting" multiple-choice questions. You should be able to get a good score if you calm down and identify them one by one.

Next, I will talk about a few questions that I didn’t answer very well at the time. I took note of them and would like to share them with you.

1. The difference and connection between processes and threads

This is actually a question about the operating system. I was confused at the time, but later I thought about it carefully and answered it based on my own understanding. Here is a slightly more complete answer. You can prepare it so that you can give a perfect answer next time you are asked this kind of question.

A process is a program with certain independent functions that runs on a certain data set. A process is an independent unit for resource allocation and scheduling in the system. A thread is an entity of a process and the basic unit for CPU scheduling and dispatching. It is a basic unit that is smaller than a process and can run independently. A thread itself basically does not own system resources, but only has some resources that are essential for operation (such as a program counter, a set of registers and a stack), but it can share all the resources owned by the process with other threads belonging to the same process.

A thread can create and cancel another thread; multiple threads in the same process can execute concurrently.

2. The difference between parallelism and concurrency

Concurrency means two or more events occur at the same time;

Concurrency occurs when two or more events occur within the same time interval.

3. Talk about your understanding of Block and delegate

I answered like this at the time: the delegate callback is more process-oriented, while the block is result-oriented. If you need to be notified of a multi-step process, you should use delegation. If you just want to get the information you requested (or an error message when getting the information), you should use a block. (If you combine the previous 3 conclusions, you will find that the delegate can maintain state in all events, while multiple independent blocks cannot)

4. Talk about the similarities and differences between instancetype and id

a. Similarities

Can be used as the return type of a method

b. Differences

①instancetype can return an object of the same type as the class in which the method is located, while id can only return an object of an unknown type; ②instancetype can only be used as a return value, not as a parameter like id

5. Can declaration attributes be used in categories? Why? If so, how can it be implemented?

When I asked this question, I felt that it could be done, but I didn't know how to do it. Later, I came back to check and found that it required the knowledge of Runtime.

Adding attributes to a category

Using Runtime to implement getter/setter methods

  1. @interface ClassName (CategoryName)@property (nonatomic, strong) NSString *str;@ end //Implementation file #import "ClassName + CategoryName.h" #importstatic void *strKey = &strKey;
  2. @implementation ClassName (CategoryName)
  3. -(void)setStr:(NSString *)str
  4. {
  5. objc_setAssociatedObject(self, & strKey, str, OBJC_ASSOCIATION_COPY);
  6. }
  7. -(NSString *)str
  8. {
  9. return objc_getAssociatedObject(self, &strKey);
  10. }
  11. @ end  

6. The difference between isKindOfClass and isMemberOfClass

This question is simple, but I was nervous at the time, so don’t answer it the wrong way.

isKindOfClass determines whether an object is a member of a class, or a member derived from that class.

isMemberOfClass can only determine whether an object is a member of the current class

7. How to prevent retain cycles in blocks

Use weak references to break retain cycles in blocks

In MRC, _block will not cause retain; but in ARC, _block will cause retain. In ARC, _weak or __unsafe_unretained weak references should be used.

8. What are the implementation methods of iOS multithreading? What queues are there in GCD? Are they parallel or serial?

There are three main multithreaded programming tools in iOS:

  1. NSThread
  2. NSOperation
  3. GCD

Dispatch queues are divided into the following three types: The system defaults to a serial queue main_queue and a parallel queue global_queue:

There are several queue types in GCD:

The main queue: has the same functionality as the main thread. In fact, tasks submitted to the main queue will be executed in the main thread. The main queue can be obtained by calling dispatch_get_main_queue(). Because the main queue is related to the main thread, it is a serial queue.

Global queues: Global queues are concurrent queues and are shared by the entire process. There are three global queues in the process: high, medium (default), and low priority queues. You can call the dispatch_get_global_queue function to pass in the priority to access the queue.

User queue: User queue (GCD does not call this queue, but there is no specific name to describe this queue, so we call it user queue) is created using the function dispatch_queue_create

Created queues: These queues are serial. Because of this, they can be used to implement synchronization mechanisms, a bit like mutexes in traditional threads.

9. Talk about the difference between load and initialize

When I asked this question, I was really confused. Although I use them a lot, I have never paid attention to the comparison between them. It seems that I should ask more questions when studying!

10.Is Core Data a database? What are the important classes?

When I saw the question, I paid attention and felt that it was not common sense. I thought about it carefully and realized that Core Data is indeed not a database. It just maps tables and OC objects. It is not as simple as entering and mapping. The underlying layer still uses Sqlite3 for storage, so Core Data is not a database.

There are 6 important classes:

(1) NSManagedObjectContext (managed data context)

  • Operation actual content (operation persistence layer)

Function: insert data, query data, delete data

(2) NSManagedObjectModel (managed data model)

  • All tables or data structures in the database, including definition information of each entity

Function: Add entity attributes and establish relationships between attributes

How to do it: View editor, or code

(3)NSPersistentStoreCoordinator (persistent storage assistant)

  • Equivalent to a database connector

Function: Set the name, location, storage method, and storage time of the data storage

(4)NSManagedObject (managed data record)

  • Equivalent to table records in the database

(5)NSFetchRequest (request to obtain data)

  • Equivalent to the query statement

(6)NSEntityDescription(Entity structure)

  • Equivalent to table structure

The above are the questions I encountered in the interview in March that I didn’t answer all or didn’t answer well at once. If you know all of them, please ignore them. Then there are 2 open questions, which basically test your ability and the depth of your understanding. One is to talk about your understanding of Runtime, and the other is to talk about your understanding of Runloop. Since I don’t have a deep understanding of these two, I won’t post my understanding here. If you feel that you are lacking, go to the Internet and read more!

11. What should you pay attention to when using sprintf, strcpy, and memcpy?

2. Machine test

This step basically only appears in large companies, or during the re-examination, because typing code on the computer can really quickly distinguish who is good and who is bad. Of course, I also interviewed with such a company, where they gave a blank paper and had to write code by hand throughout the process. This completely tests your basic skills, because there is no code completion, and no compiler to tell you where you are wrong, so everything depends on your basic skills.

The computer test basically relies on algorithm questions. Of course, there are also algorithm questions in the last few questions of the written test, which depends on how the company arranges the interview.

Two years ago, I also interviewed for iOS. At that time, the requirements for algorithms and data structures were very low, and many interviews basically did not ask these questions. This year, there were more these questions in the interview, which made me eyes light up. I also sighed at how fast technology has developed in the past two years. Interviews now involve algorithms. The path of programmers who don’t know algorithms and data structures will become narrower and narrower.

The algorithm questions I encountered were not difficult. After all, it was not a company like BAT. The simple ones asked you to write an algorithm directly. The slightly more advanced ones required you to solve the problem after having a background. In fact, they were the same as ACM questions, but not that complicated. I will post a few paragraphs of the most frequently asked algorithms. For questions that were too difficult, you can only test your algorithm skills.

Binary search θ(logn)

Recursive Methods

  1. int binarySearch1( int a[] , int low , int high , int findNum)
  2. {
  3. int mid = ( low + high ) / 2;
  4. if (low > high)
  5. return -1;
  6. else   
  7. {
  8. if (a[mid] > findNum)
  9. return binarySearch1(a, low, mid - 1, findNum);
  10. else if (a[mid] < findNum)
  11. return binarySearch1(a, mid + 1, high, findNum);
  12. else             
  13. return mid;
  14. }
  15. }

Non-recursive method

  1. int binarySearch2( int a[] , int low , int high , int findNum)
  2. {
  3. while (low <= high)
  4. {
  5. int mid = ( low + high) / 2; //This must be placed inside while
  6. if (a[mid] < findNum)
  7. low = mid + 1;
  8. else if (a[mid] > findNum)
  9. high = mid - 1;
  10. else           
  11. return mid;
  12. }
  13. return -1;
  14. }

Bubble sort θ(n^2)

  1. void bubble_sort( int a[], int n)
  2. {
  3. int i, j, temp ;
  4. for (j = 0; j < n - 1; j++)
  5. for (i = 0; i < n - 1 - j; i++) //The outer loop can determine a bubble (largest or smallest) each time it loops, so the inner loop does not need to calculate the already arranged part
  6. {
  7. if(a[i] > a[i + 1])
  8. {
  9. temp = a[i];
  10. a[i] = a[i + 1];
  11. a[i + 1] = temp ;
  12. }
  13. }
  14. }

Quick sort call method quickSort(a,0,n); θ(nlogn)

  1. void quickSort ( int a[] , int low , int high)
  2. {
  3. if (high < low + 2)
  4. return ;
  5. int start = low;
  6. int   end = high;
  7. int   temp ;
  8. while (start < end )
  9. {
  10. while ( ++start < high && a[start] <= a[low]); //Find the first position start with a value greater than a[low]
  11. while ( --end > low && a[end] >= a[low]); //Find the first position with a smaller value than a[low] end  
  12. //At this point, a[ end ] < a[low] < a[start], but the physical position is still low < start < end , so next swap a[start] and a[ end ], so that all the values ​​in the interval [low, start] are smaller than a[low], and all the values ​​in the interval [ end , hight] are larger than a[low]
  13. if (start < end )
  14. {
  15. temp = a[start];
  16. a[start]=a[ end ];
  17. a[ end ] = temp ;
  18. }
  19. //Under the GCC compiler, this method cannot achieve the purpose of exchange, a[start] ^= a[ end ] ^= a[start] ^= a[ end ]; compiler problem
  20. }
  21. //At this point, the numbers in the interval [low, end ] are all smaller than a[low], and the numbers in the interval [ end ,higt] are all larger than a[low], so just put a[low] in the middle
  22. //Under the GCC compiler, this method cannot achieve the purpose of swapping, a[low] ^= a[ end ] ^= a[low] ^= a[ end ]; compiler problem
  23. temp = a[low];
  24. a[low]=a[ end ];
  25. a[ end ] = temp ;
  26. //Now it is divided into 3 sections, separated by the initial a[low] hub
  27. quickSort(a, low, end );
  28. quickSort(a, start, high);
  29. }

I have also written the notes. These algorithms can basically handle simple algorithm problems.

For the data structure question, I encountered linked list reversal, implementing a stack structure, first-in, last-out, tree traversal, DFS and BFS of the graph. I won't post the code because it's too long. If you forget anything, you can go back and review it.

3. Interview

The interview will basically ask you what projects you have done before, what problems you have encountered, how you solved them, what you think of XXX, etc. As long as you complete the projects seriously, the questions in the interview will be easier to answer, because they are all about your projects, which you know best.

Well, this is the situation of recruiting iOS development engineers in Shanghai in February 2018, except for BAT companies. Compared with two years ago, the biggest experience is that the interviews are wider and the requirements are higher. Now, in addition to knowing OC, you must also understand algorithms and data structures, and either know ReactNative or a series of hybrid development frameworks such as PhoneGap, or be familiar with Swift. Programmers must keep up with the mainstream to avoid being eliminated by the times. Only in this way can they be competitive. This is also my feeling after interviewing these companies. You can learn as long as you live! Finally, I hope everyone can communicate with me. I am also an iOS rookie. Please give me more advice!

<<:  Tencent's top 10 open source projects for WeChat and mobile development

>>:  A cheap iPhone X at half the price won't save Apple

Recommend

The dwarf killer: the African pygmy falcon

When we talk about birds of prey, we will definit...

iOS 15.5 quasi-official version released

The size of this update package is about 5.2G, an...

3 Steps to User Growth Strategy

User growth strategies need to be changed accordi...

What kind of brand marketing promotion plan attracts everyone?

Brand marketing is an advanced marketing method. ...