After reading these, Dachang is not a dream!!

I just started the interview today. I will summarize the interview questions I have met in the following days as follows:

1. The application of memory management in practical development (compulsory examination, has been asked twice)

A: 1. UITableView drains memory data of the number too much, can give a UITableViewCell, UICollectionViewCell, UITableViewHeaderFooterView set the correct reuse ID, fully reuse.

2. Where there is a View with an alpha value between 0 and 1, the value of opaque should be set to YES to optimize the rendering system and improve performance. Opaque value has no effect on performance when alpha is 0 or 1.

3. Avoid large XIB/ Storybord files. When the XIB files are loaded, all the contents will be added to memory.

4. Don’t overload the main thread with too many tasks, otherwise it will block the main thread and make the app unresponsive.

5. When loading local images, make sure that the size of UIImageView is the same as the size of the image, because scaling the image is very resource-consuming, especially if the UIImageView is nested within the UIScrollView. If you load an image from the network, you can wait until the image is loaded, start a child thread to scale the image, and then place it in the UIImageView.

6. Choose the right data type in the right scenario. For arrays: fast with indexes, slow with values, slow with inserts and deletes, fast with dictionaries: fast with keys, fast with sets: fast with values, fast with inserts and deletes.

7. Compression when downloading files from the network (AFNetworking is already compressed by default)

8. When UIScrollView nested a large number of UIViews will consume memory, which can be solved by imitating the reuse method of UITableView. When network requests, lazy loading can be used to display the requested wrong page, because the wrong page will not be used immediately, and it will consume memory if it is loaded out first every time.

9. Things that are not likely to change but are frequently used can be cached, such as the row height of the cell can be cached, so that reloadData can be very efficient. There is also some network data that does not need to be requested every time, should be cached, can be written to the database, can be written to the plist file.

10. There are methods for handling memory warnings in both AppDelegate and UIViewController, registering and receiving notifications of memory warnings, and removing the cache as soon as they are received, freeing up unwanted memory space.

11. Some objects are slow to initialize, such as NSDataFormatter and NScalendar, but you have to use them. You can reuse them either by adding properties to your class or by creating static variables (like singleton).

12. The server side and the client side use the same data structure to avoid repeated data processing. Frame is used as little as possible in UIWebView, and original JS is best, because the load of UIView is slow.

13. When creating variables in the loop to process data, the use of automatic release pool can release memory in time.

14. When loading local images, use the imageWithCondentoFile method only once, because imageNamed will cache the images and consume memory.

Summary: in the interview, I only answered the difference between the principles of memory management and MRC, ARC, automatic release pool, and did not tell how memory management is used in the actual development, completely missed the point.

2. Practical application of multi-threading scenarios, back to the main thread method (compulsory test, has been asked twice)

In the actual development, there may be some time-consuming operations. In this case, a child thread can be created to put the time-consuming operations into the child thread. When the time-consuming operations are completed, the main thread can be returned to refresh the UI. You must refresh the UI on the main thread, because multithreading is not safe, and if you refresh the UI in a child thread, it may cause an unknown error.

Back to the main thread of the method is performSelectorOnMainTread

Delayed execution code: performSelector: onThread: withObject: waitUntillDone:

Return to the main thread using GCD: dispatch_get_main_queue()

Start the thread with GCD: dispatch_async

The difference between the two: dispatch_async() is not affected by the running loop mode

Conclusion: I only answered the concept of multithreading, the advantages, but the interviewer mainly want to hear the key words: time, start child threads, go back to the main thread refresh UI, so irrelevant answer, and go back to the main thread method name I did not remember. This is an important question to keep in mind in almost any iOS technology interview.

3. Understanding of GCD

A: There are two core concepts in the GCD, queues and tasks. The queue holds the tasks, and the retrieval of the tasks follows the FIFO principle. Queues are actually thread pools, represented by dispatch_queue_t in OC. Queues can be divided into serial queues and concurrent queues. A task is simply code executed by a thread, represented in OC as a Block. There are two ways to execute tasks on a queue: synchronously and asynchronously.

Serial Queue: Tasks are executed one by one.

Concurrent Queue: Multiple tasks are being executed at the same time.

(Concurrent queue is a process where one task is taken from another thread and another task is taken from another thread. Because the process is so fast that it is negligible, it looks like all tasks are executed together.)

Synchronous execution: No new threads are started. Tasks are executed sequentially.

Asynchronous execution: New threads are started and tasks can be executed concurrently.

Difference: whether a new thread is started or not.

Combination:

Synchronous serial queue: one by one (because the previous task does not complete, the queue is not scheduled) synchronous parallel queue: one by one (because synchronous execution does not start a new thread) asynchronous concurrent queue: enables concurrent tasks and is often used

Main queue: The main queue is a serial queue with only one thread, the main thread, on which tasks added to the main queue are executed. Get the main queue via DISPATCH_GET_MAIN_QUEUE.

Global queue: A global queue is a concurrent queue. Global queues of different levels can be obtained through dispatch_get_global_queue.

Synchronize main queue: deadlock does not execute. Main queue asynchronous: one by one (because no new thread is started)

Conclusion: I only answered the delayed operation using GCD and dispatch_after method when loading animation, which were all too superficial. The interviewer wanted to hear a deeper understanding, so he asked me about tasks and queues. I didn’t think of this aspect, and when I mentioned GCD, the first thing I would think of is tasks and queues. Because tasks and queues are the core concepts of the GCD.

4. The difference between TCP, HTTP and WebSokect

A: IP protocol (network layer protocol) TCP: transmission control protocol, mainly to solve how data transmission in the network, connection-oriented, reliable. (Transport Layer Protocol) UDP: User Datagram Protocol, datagram oriented, unreliable. HTTP: Focuses on how to wrap data. Socket is the encapsulation of TCP/IP protocol. Socket itself is not a protocol, but a call interface (API). Through Socket we can use TCP/IP protocol. (Transport Layer Protocol)

HTTP connection: a short connection in which the client sends a request to the server and the server responds to the connection and terminates immediately. Socket connection: a long connection. Theoretically, once the connection between the client and server is established, it will not be terminated actively.

At least one pair of sockets is required to establish a Socket connection, one running on the client side, called ClientSocket, and one running on the server side, called ServerSocket. The connection process between sockets is divided into three steps: the server listens, the client requests, and the connection confirms.

WebSocket is a two-way communication protocol that simulates the Socket protocol and can send and receive messages in both directions. HTTP is one-way. Socket is a Transport Control Layer protocol, WebSocket is an Application Layer protocol.

Conclusion: I don’t understand what I wrote on my resume, it’s embarrassing, even if I can’t say something deep, I should say the main difference between them. And the seven-tier model of the network. Remember, the interviewer asked me this a few years ago and I didn’t remember it.

From the bottom to the top, there are physical layer, data link layer, network layer, transmission layer, session layer, presentation layer and application layer.

5. What is the most important aspect of the iOS application life cycle

Application: application: willFinishLaunchingWithOptions: process began didFinishLaunchingWithOptions: Entrance, executed only once, the start finish ready to start running applicationWillResignActive: switch to the inactive state, such as pressing the home button, switch program applicationDidBecomeActive: Switch to the activated state applicationDidEnterBackground: applicationWillEnterForeground application into the background, the application will be activated applicationWillTerminate: The application is about to exit

Launching the App: open the App — execute main — UIApplicationMain — initialize UIApplicationMain (set proxy, open runloop) — listen for system events, notify AppDelegate — end of the App

Summary: The interviewer asked about the life cycle of the application. I asked about the life cycle of the ViewController. The key words the interviewer wants to hear are: main function, UIApplicationMain, AppDelegate, RunLoop, and Listening

In addition, to summarize the RunLoop:

Runloop is used to keep the program running continuously, handle various events in the App, and improve resource utilization. Control the thread life cycle, solve the issue of NStimer stop working when sliding, monitor application lag, optimize performance

6. Core animations for iOS (required, asked twice)

A: There are two basic types of animations: implicit (always present, need to be manually closed) and explicit (not present, need to be manually created) animations for UIView:

UIViewAnimationOptionCurveEaseInOut / / time curve function, from slow to fast

UIViewAnimationOptionCurveEaseIn / / time curve function, from slow to particularly fast

UIViewAnimationOptionCurveEaseOut / / time curve function, from fast to slow

UIViewAnimationOptionTransitionFlipFromLeft / / transitions from left turn

UIViewAnimationOptionTransitionFlipFromRight / / transitions from right turn

UIViewAnimationOptionTransitionCurlUp / / coil transitions

UIViewAnimationOptionTransitionCurlDown / / volume transitions

Usage: animateWithDuration, transitionWithView

CAAnimation animation classification:

1. Basic animation (such as moving items in the shopping cart) 2. Key frame animation, picture frame (such as people, animals walking) (CakeyframAnimation) 3. Transition animation (from one scene to another, such as page turning) (CATransition) 4. Composite animation (CAAnimationGroup)

Values that can be animated:

1. Shape series: Frame Bounds 2. Position series: Center 3. 4. Angle Series: Transform

Conclusion: The interviewer asked me how to make a flickering effect, and I answered to change the color, but the correct answer should be to change the transparency. He also asked me what animation effects I had made, but I only answered one effect I had made. Normally, I should tell all the effects that can be achieved according to the classification of animation.

7. Upload large files

A: It can be uploaded in slices and continued at breakpoint

Conclusion: this function I have not done, did not answer, but at least should know the method of large file uploading.

I haven’t had an interview for several years. I suddenly found that I have forgotten a lot of basic knowledge, and I don’t have a thorough understanding of some concepts. I need to work hard to learn them. Although many concepts can not be used in daily work, but to understand these is the basic quality of a software engineer, even the most basic things are not, how dare to say that they have worked for several years, really ashamed ah. (If you want to become a senior software engineer, you must master the underlying principles. Only by mastering the underlying principles can you develop higher quality programs. Otherwise, no matter how many years you have worked, you will only be at the primary and intermediate level. I hope to continue to summarize experience and learn in the following interview.

. To be continued

Those who want to receive free information can enter the skirt or add friends to get it. Here is an iOS communication circle: 710 558 675, you can come to understand, share BAT, Ali interview questions, interview experience, discuss technology, skirt information directly download, everyone exchange and learn together!

Want to interview information or other information can also find me, welcome to consult! The article will continue to be updated, and you can also send me a private message for information related to the interview in time. If you have any comments and suggestions, please leave a message to me. Please pay attention to iOS friends! If you like it, give it a like! Thank you very much! Thank you very much! Thank you very much!