Gold three silver four, I believe that many people are job-hopping recently. So the interview questions naturally still want to see, in this I put my hand to collect the interview questions (friends interview, online collection, etc.) have been summarized, I hope to help you are or preparing for the interview, at the same time I can also be in their own over 😝
General Interview questions
1. The difference between heap and stack
1. Memory management Scope Only OC objects need memory management. Non-oc objects, such as basic data types, do not need memory management. Memory management is essentially because: Objective-c objects are allocated in memory in a heap, and the heap is freed by you, which is release OC objects are stored in the heap (heap memory has to be reclaimed manually by the programmer) and non-OC objects are stored in the stack (stack memory is automatically reclaimed by the system) and memory in the heap is allocated dynamically, Therefore, the programmer needs to manually add and reclaim memory 3. Memory allocation and management By allocation The heap is allocated and reclaimed dynamically. The heap without static allocation can be allocated in two ways: The static distribution and dynamic allocation Accomplished statically allocated is the compiler system, such as the distribution of the local variable dynamic allocation is alloc function allocation, but the dynamic allocation of stack and heap is different, its dynamic allocation are also released by the system to the compiler, don’t need programmers manual management According to the management way For the stack, For the heap, the release work is manually managed by the programmer, not timely collection is prone to memory leakage heap: is the common space, divided into the global heap and local heap. The global heap is all unallocated space, and the local heap is user-allocated space. The heap is allocated when the operating system initializes the process. You can also ask the system for extra heap during the run, but remember to return it to the operating system when you run out, or else it will leak memory. The heap usually contains static data, such as static data and string constants, etc. Resources are also stored in the heap after loading. These heaps are shared by all threads of a process, so operations on the heap need to consider synchronization and mutual exclusion. All compiled data segments in the program are part of the heap. Stack: a thread-specific stack that holds its running state and local automatic variables. The stack is initialized at the start of a thread. Each thread’s stack is independent of each other, so the stack is Thread safe. The data members of each c++ object also exist in the stack, and each function has its own stack, which is used to pass parameters between functions. The operating system will automatically switch stacks when switching threads, that is, switch SS/ESP registers. Stack space does not need to be explicitly allocated or freed in a high-level language. Stack: allocated and freed automatically by the compiler, usually holding parameter values, local variables
2. KVO and KVC
KVC, which stands for NSKeyValueCoding, provides a mechanism for indirectly accessing an object’s properties. KVC is based on KVO technology to achieve. KVO, which provides an observer mechanism by adding an observer to an attribute of an object, calls the “observeValueForKeyPath:” method when the attribute changes.
- What is the method of creating threads in OC? If you execute code in the main thread, what is the method? What is the method if you want to delay code execution?
1. There are three ways to create a thread: using NSThread, using GCD dispatch, subclassing NSOperation, and adding it to NSOperationQueue; 2, in the main thread to execute code, the method is performSelectorOnMainThread: withObject: waitUntilDone:; 3, if you want to delay implementation code can use the performSelector: onThread: withObject: waitUntilDone:;
4. How do Pointers relate to array names?
int arrayName[4] = {10, 20, 30, 40}; int *p = (int *)(&arrayName + 1); NSLog(@”%d”, (&arrayName – 1)); 1.(&arrayName + 1) : &arrayName is the address of array (equivalent to a pointer to arrayName) 2. An increase of 1 will move 16 bytes back, starting at 4 bytes and ending at 16 bytes (the current position is 20 bytes) 3. And finally, we’ll assign p to int 4. Int *p = (int *)(&arrayName + 1); arrayName = (arrayName + 1); NSLog(@”%d”, *(p – 1)); // The output is 40
5. What is the difference between #import and #include? @ the class? Is there any difference between #import <> and #import””?
Use #import to import only once, which is equivalent to #include and #pragma once. @class is generally used to declare a string as a class name. It simply declares a class name, does not import the contents of a. H file, and does not cause cross-compilation problems. > < span style = “max-width: 100%; clear: both; min-height: 1em
6. Attribute readwrite. Readonly, assign, retain, copy, nonatomic what role? In which case?
Readwrite is readable and writable. When you need to generate getter and setter methods (add: default property that generates getter and setter methods with no additional arguments (setter methods have only one argument) readonly is a read-only property that generates getter methods but not setter methods; Assign is an assignment property that you don’t want to change outside of the class. Setter methods assign incoming parameters to instance variables. When only variables are set; Retain means hold property. Setter methods retain and assign the value of the passed parameter. Retaincount of the passed parameter is +1. Copy is the copy property. Setter methods make a copy of the object passed in. Need a complete new variable. Nonatomic operation, which determines whether the setter getter generated by the compiler is atomic or not. Atomic means multithread safe and nonatomic is generally used
7. Why can the view attribute connected by IBOutlet be set to weak?
Adding a control reference to a storyboard looks like this (in the case of UIbutton): UIviewController -> UIview -> UIbutton now UIviewController is strongly referencing UIview, UIview is strongly referencing UIbutton, An IBoutlet wired to a controller’s.m or.h as a view property is weak, and an IBoutlet added to a child control is strong: UIbutton is just a view that’s added to UIviewController
The preposition define declares a constant to indicate how many seconds are in (leap problem).
define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
9. Rewrite – NSString retain setter and getter (MRC) for name property
Properties have three major properties: semantic properties, atomic properties, read and write properties. Override setter and getter methods @synchronized name = _name, associated properties and instance variables such as -(void)setName:(NSString *)name{if(_name! = name){ [_name retain]; [_name release]; _name = name; } } -(NSString *)name{ return [[_name retain]autorelease] }
10. Analyze the difference between JSON and XML? How is the underlying parsing of JSON and XML processed
(1) The differences between JSON and XML: (1) readability: basically the same, XML readability is better; (2) Scalability: both have good scalability; (3) Coding difficulty: JSON coding is relatively easy; (4) Decoding difficulty: JSON decoding difficulty is basically zero, XML needs to consider child nodes and parent nodes; (5) Data volume: COMPARED with XML, JSON has smaller data volume and faster transmission speed; (6) Data interaction: the interaction between JSON and javascript is more convenient, easier to parse and process, and better data interaction; (7) Data description: XML has a better description of data. (8) Transmission speed: JSON is much faster than XML. (1) The basic principle of JSON: iterates the characters in the string, and finally distinguishes the characters according to the special characters specified in the format, such as {}, [], :, etc. {} indicates the dictionary, [] indicates the array, : The number is the distinction between the key and the value of the dictionary, which ultimately converts JSON to a dictionary, but the value of the dictionary might be “just a dictionary, an array, or a string.” (2) UNDERLYING PRINCIPLES of XML: there are two common parsing methods for XML parsing: DOM parsing and SAX parsing; DOM uses a tree structure to access XML documents, while SAX uses an event model. DOM parsing transforms XML documents into a tree containing their contents, and traverses the tree. When using DOM parser, you need to process the entire XML document, so it has high requirements on memory and performance. SAX can trigger a series of events as it parses an XML document. When a given tag is found, it can activate a callback method that tells the method that the specified tag has been found. SAX’s memory requirements are usually low because it lets developers decide which tags to process. SAX’s extensibility is especially good when the developer only needs to work with part of the data contained in the document.
11. What suggestions do you have for optimizing application performance?
1. Use reuse mechanism 2. Make View as opaque as possible 3. 5. Image size matches UIImageView 6. Select the appropriate container 7. Enable GZIP data compression 8. Reuse and lazy loading mechanism of View 9. The image. The calculated value. For example: UITableView’s Row heights. 11. 10. About graphic drawings processing Memory Warnings in the AppDelegate implementation – [AppDelegate applicationDidReceiveMemoryWarning:] proxy method. Override the didReceiveMemoryWarning method in UIViewController. Listening UIApplicationDidReceiveMemoryWarningNotification notice. Reuse objects with high overhead 13. Reduce off-screen rendering (you can use the drawing method when setting rounded corners and shadows) 14. Optimize UITableView to reuse cells by properly setting the reuseIdentifier. Minimize unnecessary transparent views. Try to avoid gradient effects, image stretching, and off-screen rendering. When different rows have different heights, try to cache their height values. If the Cell presents content from the network, make sure to load the data asynchronously and cache the server’s response. Use shadowPath to set shadow effects. Minimize the number of subviews. For cells with a large number of subviews and variable styles, consider asynchronous drawing or rewriting drawRect. Try to optimize – [UITableView tableView: cellForRowAtIndexPath:] processing logic in the method, if you really want to do some processing, can consider to do a, cache the results. Choose the right data structure to carry the data. Different data structures have different overhead for different operations. Use constants for rowHeight, sectionFooterHeight, and sectionHeaderHeight. 15. Select an appropriate data storage mode. In iOS, you can use NSUserDefaults to hold data. Only good for storing small data. XML, JSON, and Plist files. The difference between JSON and XML files was covered in “Choosing the right data format.” Use NSCoding for archiving. NSCoding also reads and writes files, so it faces the problem of having to load the entire file to continue. Use the SQLite database. Can be used with FMDB. Data relative to the file or many benefits, such as on-demand data, not violent search and so on. Use CoreData. Also a database technology, the performance difference is relatively small compared to SQLite. But CoreData is an object graph model, which is more object-oriented; SQLite is just a regular DBMS. 16. Reduce app startup time Launching an app quickly makes a good impression on users. Especially the first time you use it. Guidelines for fast startup: Try to break up the startup process into asynchronous processing streams, such as network requests, database access, data parsing, and so on. Avoid bloated XIB files because they will be loaded in your main thread. Again: This is not a problem with storyboards. Note: When testing program startup performance, it is best to test it on a device disconnected from Xcode. Because watchdog does not start when debugging with Xcode. ImageNamed and imageWithContentsOfFile
12. What does runloop have to do with threads?
Runloops correspond to threads one by one. A runloop corresponds to a core thread, which is core because runloops can be nested, but there can only be one core, and their relationship is stored in a global dictionary. Runloop is used to manage threads. When a thread’s Runloop is enabled, the thread will go to sleep after executing a task. When a task is available, the thread will be awakened to perform the task. The runloop is created on the first fetch and destroyed at the end of the thread. For the main thread, the runloop is created by default as soon as the program starts. For child threads, runloops are lazily loaded and only created when we use them, so be careful when using timers on child threads: make sure the runloop is created for the child thread, otherwise the timer will not call back.
13 Introduce layoutSubview and drawRect
LayoutSubviews calls init does not trigger a call when you initialize UIView addSubview does trigger a call when you change the width and height of the view a UIScrollView will trigger a call when you scroll it will trigger a call when you rotate screen Changing the size of a UIView triggers the superView’s layoutSubviews event and calling setLayoutSubviews directly triggers the call -(void)viewWillAppear:(BOOL)animated triggers a call -(void)viewDidAppear:(BOOL)animated might call drawRect if UIView doesn’t set the frame size, so drawRect can’t be called automatically. DrawRect is called after loadView and viewDidLoad and automatically called after sizeToFit by setting the contentMode value to UIViewContentModeRedraw. DrawRect is automatically called every time you set or change the frame. Calling setNeedsDisplay or setNeedsDisplayInRect directly triggers the call
14. Write a “standard” macro MIN that takes two arguments and returns the smaller one
MIN(A,B) ((A) <= (B) ? (A) : (B))
15. What are categories for
1. Extend existing classes (add methods) 2
- What is Method Swizzing? Tell me about your situation and what to pay attention to
1. Add attributes to extensions. 2. Replace the implementation of system methods
22. Explain how iOS event response chains work
1. Responder chains are usually made up of UIViews; 2. The next responder to a View is its ViewController (UIViewController) (if any), which then passes to its Super View; 3. The next responder of the view controller (if any) is the parent view of the view it manages; 4. The content view of a singleton window (UIWindow) points to the window itself as its next responder. It should be noted that Cocoa Touch applications, unlike Cocoa applications, have only one UIWindow object, so the whole responder chain is a bit simpler; 5. A singleton application is the end of a responder chain, and its next responder points to nil to end the loop.
23. When do you choose Category
1. Extend existing classes (add methods)
24. What is the relationship between UIview and CAlayer? What did you CLayer do?
- First UIView can respond to events, Layer can’t.
- UIView is a delegate for CALayer. 3. UIView handles events and CALayer draws. Each UIView has a CALayer behind it to draw and display the content, and the size styles of UIView are provided by the Layer inside. Both have tree hierarchies, with SubLayers inside the layer and SubViews inside the View. But Layer has one more AnchorPoint than View to create implicit animations to draw border rounded corners
25. How to solve the problem of dynamically calculating the height of cells in UITableVier?
1. Your Cell must use AutoLayout for layout constraints. Set the TableView estimatedRowHeight to a non-zero value. This property sets an estimated height, not too precise. Set the tableview rowHeight attributes to UITableViewAutomaticDimension 2. The third party UITableView + FDTemplateLayoutCell
26. What is the priority in AutoLayout? What are the problems with using Autolayout in UIScrollView?
Frame -> Autoreszing -> Autolayout -> Sizeclass allows you to set two constraints that appear to conflict with each other, but not with different priorities. When one of the constraints fails, another constraint of lower priority takes effect
27. What is the difference between NSIRLConnection and NSLRLSession? What does NSURLProtocol do?
When NSURLConnection downloads files, the entire file is first downloaded to memory, and then written to the sandbox. If the file is large, the memory will be inflated. NSURLSessionUploadTask (NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask, NSURLSessionUploadTask) Add code 2 to save the file in the completionHandler callback. Control of the request method NSURLConnection instantiates the object, and when instantiation begins, the default request is sent (synchronously) without calling the start method. Cancel can stop the sending of the request. After the stop, the access cannot be continued and a new request needs to be created. NSURLSession has three control methods: Cancel, suspend, and resume. After suspension, you can resume the current requested task by resuming it. Using NSURLSession for breakpoint download is more convenient. NSURLSession constructor (sessionWithConfiguration: delegate: delegateQueue) have a NSURLSessionConfiguration class parameter can be set in the configuration information, determining the cookie, Security and cache policies, maximum number of host connections, resource management, network timeout, etc. NSURLConnection can’t do this configuration, which is a big improvement over NSURLSession’s lack of flexibility compared to NSURLConnection’s reliance on a global configuration object
28. How to effectively realize the rounded corner effect of the control
To draw the rounded – (UIImageView *) roundedRectImageViewWithCornerRadius: CGFloat cornerRadius {UIBezierPath * bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius]; CAShapeLayer *layer = [CAShapeLayer layer]; layer.path = bezierPath.CGPath; self.layer.mask = layer; return self; }
What do you know about weak attributes?
The weak keyword is relatively basic in OC. This property indicates that it defines a “nonowning relationship”. When you set a new value for this property, the setting method neither preserves the new value nor releases the old value. This is similar to assign, but the value of the attribute is nil out when the object to which it refers is destroyed. Weak references do not determine the survival of the object. Even if an object holds numerous weak references, as long as no strong references point to it, it will still be removed.
33. If Controller is too bloated, how to optimize it?
1. Abstracting network requests into separate classes to facilitate processing of common logic in base classes; Easy to handle caching logic in base classes, as well as other common logic; Easy to do object persistence. 2. Abstract the interface encapsulation into a special class to construct a special UIView subclass to be responsible for the assembly of these controls. This is the most thorough and elegant way to do this, but it is a little more troublesome because you need to take over the control’s event callbacks and then expose them all back to the Controller. 3. Construct ViewModel according to MVVM. The idea is to abstract the process of passing the ViewController to the View into the process of constructing the ViewModel. 4. Build storage classes specifically to handle local data access. 5. Integrate constants
34. How to deal with the security of the network layer in the project?
1. Determine whether the API call request is from an authorized APP. 2. Encrypt URLS during data requests to prevent decomcompiling and static analysis of interface information. 3. Data transmission encryption: Provides an effective encryption scheme for data transmitted by clients to prevent interception by network interfaces. If HTTPS is used as much as possible, interface data can be effectively prevented from being attacked during transmission.
35. What are the processes before main()?
In iOS, main.m is a familiar entry point. But the program did a lot of work before that. For example, the system obtains the dyLD path and loads it. Load the dependent libraries in the program. Call all the + load methods and return the main address.
Other summaries worth looking at:
We are looking for a reliable iOS candidate
BAT interview questions
Said by: Thomas Edison, who did not understand technology
1. Tencent uses third-party libraries, have you seen how they are implemented? 2. Do you know the strong connection flux algorithm? 3. Do you encounter tableView lag? What are the causes of the problem? 4. What rules do you know about the communication between M, V and C? 5. NStimer accurate? What’s your opinion? How do you implement an accurate NSTimer if not? The answer can be found in the: https://www.jianshu.com/p/0e9e7486e1a7
1. What does the compilation process do? 2. The general implementation principle of the dictionary; 3. Understanding of blocks and function Pointers; 4. How do you think about your architecture when you start a project? 5. What do you know about UIKit structure? The answer can be found in the: https://www.jianshu.com/p/dd17bdcff9f7
1.OC What locks do you know? Ask a second question based on your answer; Question 1: Spin and mutex contrast? Question 2: Use C/OC/C++, one or the other, to implement spin or mutex? Dictate! 2. What is your opinion on the possible causes of memory leakage? Follow-up Question 1: How to deal with non-OC objects? Follow-up Question 2: How to deal with memory leaks in common frameworks? What do you usually do? 4. Have you handled the fault tolerance at the beginning of the project? How do I prevent interception from potentially crashing? The answer can be found in the: https://www.jianshu.com/p/3a50d1805655
Ali 1. DSYM How do you analyze it? 2. What kinds of multithreading are there? Which one do you prefer? 3. Disadvantages of singleton? 4. How to convert asynchronous threads into synchronous tasks for unit testing? 5. Introduce the completion process of App startup? 6. For example, if the App starts too slowly, what factors might you think of? What is 7.0 x8badF00d? 8. How to prevent decompilation? 9. Tell me about the technical difficulties you have encountered. 10. Tell me about third party principles or low-level knowledge you have. The answer is http://url.cn/5oWSdgZ
Other more BAT interview can link: https://pan.baidu.com/s/1zTjFig0R4MdtBJdZIdfJug password: rbta download