In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the advanced iOS interview questions". In the daily operation, I believe many people have doubts about the advanced iOS interview questions. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the advanced iOS interview questions?" Next, please follow the editor to study!
1. What is the difference between NSArray and NSSet?
NSArray memory address is contiguous, but NSSet is not contiguous
NSSet is efficient and uses hash lookup internally; NSArray lookup requires traversal
NSSet accesses elements through anyObject, and NSArray accesses elements through subscripts
2. NSHashTable and NSMapTable?
NSHashTable is a general-purpose version of NSSet, with weak references to elements and variable types; you can copy when accessing members
NSMapTable is a general-purpose version of NSDictionary, with weak references to elements and variable types; you can copy when accessing members
(note: the difference between NSHashTable and NSSet: NSHashTable can set the element weak reference / copyin through option, with only mutable types. But NSHashTable takes twice as long as NSSet to add objects.
The difference between NSMapTable and NSDictionary: ditto)
3. Attribute keywords assign, retain, weak, copy
Assign: for basic data types and structures. If the object is modified, the property value will not be automatically set to nil when destroyed, which may result in a wild pointer.
Weak: when the object reference count is 0, the attribute value is also automatically set to nil
Retain: strong reference type, which is equivalent to strong under ARC, but block cannot be decorated with retain because it is equivalent to assign is unsafe.
Strong: strong reference type, which is equivalent to copy when decorating block.
4. How does the weak attribute set nil automatically?
Runtime lays out the memory of the weak property and builds the hash table: take the memory address of the weak property object as the key,weak attribute value (the weak itself address) as the value. When the object reference count is 0 dealloc, the value of the weak property is automatically set to nil.
5. Circular reference of Block, internal modification of external variables, and three kinds of block
Block strong reference self,self strong reference block
Modify external variables internally: block does not allow you to modify the values of external variables, which refer to the memory address of the pointer in the stack. The purpose of _ _ block is to put the memory address of the external variable in the stack on the heap as soon as it is observed that the variable is being used by block.
Three kinds of block:NSGlobalBlack (global), NSStackBlock (stack block), NSMallocBlock (heap block)
6. The underlying implementation principle of KVO? Manually trigger KVO? How does swift implement KVO?
KVO principle: when observing an object, runtime will dynamically create a class inherited from the object and rewrite the setter method of the observed object. The rewritten setter method will be responsible for notifying all observation objects before and after calling the original setter method that they are worth changing. Finally, the isa pointer of the object will be pointed to the created subclass, and the object will become an instance of the subclass.
How to trigger KVO manually: in the setter method, implement two methods of NSObject manually: willChangeValueForKey and didChangeValueForKey
Swift's kvo: a class that inherits from NSObject, or a direct willset/didset implementation.
7. Why can't categroy add attributes? How to add? What's the difference from Extension? Category overrides the original class method? Multiple category call order
The memory layout of the categroy is determined when Runtime is initialized, and there is no ivar, so attributes cannot be added by default.
Use the associated object of runtime and override the setter and getter methods.
Extenstion is created at compile time, and the member variable ivar can be added, which is generally used as information about hidden classes. You must have the source code of a class before you can add it. For example, NSString cannot create an Extension.
The category method will copy in front of the original when the runtime is initialized, and return directly when the classification method is called, instead of calling the original class. How to keep the original class also called (https://www.jianshu.com/p/40e28c9f9da5).
Multiple category calls are made in the order of compilation in: Build Phases-> Complie Source.
8. The similarities and differences between load method and initialize method. -- mainly talk about the execution time, their respective uses, and whether the methods that do not implement the subclass will call the parent class?
Timing of load initialize call after app starts, when runtime initializes, the first method is called before calling sequence parent class-> this class-> classification parent class-> this class (if classification is called directly, this class will not call this class) whether the method that does not implement the subclass will call the parent class whether to follow the parent class or not
Image
9. Understanding of runtime. -- mainly about how to find the cache when the method is called, how to find the method, how to forward it when the method is not found, and the memory layout of the object
When sending a message to an object in OC, runtime finds the class to which the object belongs according to the object's isa pointer, and then looks for method execution in the method list of that class and in the method list of the parent class. If no method execution is found in the topmost parent class, message forwarding occurs: Method resoution (implementation method), fast forwarding (forwarded to other objects), normal forwarding (full message forwarding). Can be forwarded to multiple objects)
10. What is the difference between SEL and IMP in runtime?
Each class object has a method list, which stores the method name, method implementation, and parameter type. SEL is the method name (number), and IMP points to the first address of the method implementation.
11. What is the principle and usage scenario of autoreleasepool?
Stack structure of two-way linked list composed of several autoreleasepoolpage, objc_autoreleasepoolpush, objc_autoreleasepoolpop, objc_autorelease
Usage scenario: delayed release is required when memory rises due to the creation of temporary variables multiple times
Memory structure of autoreleasepoolpage: 4k storage size
Image
12. When will the Autorelase object be released?
In the absence of hand-added Autorelease Pool, the Autorelease object is released at the end of the current runloop iteration, and it can be released because the system adds automatic release pools Push and Pop in each runloop iteration.
13. The relationship between Runloop and threads? Runloop's mode? What is the role of Runloop? Internal mechanism?
Each thread has a runloop, and the runloop of the main thread starts by default.
Mode: mainly used to specify the priority of the event loop at run time
Function: keep the program running continuously, deal with all kinds of events at any time, save cpu resources (release resources without event break), render screen UI
14. Occurrence and avoidance of locks and deadlocks used in iOS
@ synchronized, semaphore, NSLock, etc.
Deadlock: multiple threads access the same resource at the same time, causing a loop to wait. GCD uses asynchronous threads, parallel queues
15. The difference between NSOperation and GCD
The bottom layer of GCD uses C language to write efficiently, and NSOperation is the object-oriented encapsulation of GCD. For special requirements, such as canceling tasks, setting task priorities, and monitoring task status, NSOperation is more convenient to use.
NSOperation can set dependencies, while GCD can only be implemented through dispatch_barrier_async
NSOperation can observe the current operation execution status through KVO (execute / cancel)
NSOperation can set its own priority (queuePriority). GCD can only set queue priority (DISPATCH_QUEUE_PRIORITY_DEFAULT), but cannot set priority in the executing block
NSOperation can customize operation such as NSInvationOperation/NSBlockOperation, while GCD execution tasks can be customized but do not have that high code reuse
GCD is efficient and NSOperation overhead is relatively high.
16. Oc interacts with js
Intercept url
JavaScriptCore (for UIWebView only)
WKScriptMessageHandler (for WKWebView only)
WebViewJavaScriptBridge (third-party framework)
17. What are the advantages of swift over OC?
18. The difference between struct and Class
Class can inherit, but struct cannot
Class is a reference type and struct is a value type
Struct needs mutating keyword modification when modifying property in function
19. Access control keywords (public, open, private, filePrivate, internal)
Public and open:public inside module, class and func can be accessed / overloaded / inherited, external can only be accessed, while open can
Private and filePrivate:private modify class/func, indicating that it can only be used inside the current class source file / func, and cannot be inherited and accessed externally, while filePrivate means that it can only be accessed within the current swift source file.
Internal: can be accessed within the whole module or app. The default access level is writable or unwritable.
20. Mixed OC and Swift
OC calls swift:import "project name-swift.h" @ objc
Swift calls oc: bridge file
21 、 map 、 filter 、 reduce? The difference between map and flapmap?
Map: each element in the array is converted by some method, and a new array is returned (xx.map ({
0}))
Flatmap: similar to map, except that the array returned by flatmap does not exist nil and unpacks optional. Moreover, you can open the nested array into one ([[1meme2], [2meme3rect 4], [5core6]]-> [1mine2min2men3mine45pyr6])).
Filter: user filter elements (xxx.filter ({$0 > 25}), filter out elements greater than 25 to form a new array)
Reduce: evaluates the combination of array elements to a value and receives the initial value ()
Image
22. Guard and defer
Guard is used to process error data in advance, and else exits the program to improve the readability of the code.
Defer delays execution and reclaims resources. Multiple defer are executed in reverse order. The nested defer executes the outer layer first and then the inner layer.
23 、 try 、 try? With try!
Try: catching exceptions manually
The try?: system handles it for us. If an exception occurs, it returns nil;. No exception returns the corresponding object.
Trykeeper: tell the system directly that there is no exception in this method. If an exception occurs, the program will crash
24, @ autoclosure: automatically encapsulates an expression into a closure
25. When throws and rethrows:throws have another throws, change the former to rethrows
26. App initiates optimization strategy? How to optimize main function before and after execution
Startup time = pre-main time + main time
Pre-main phase optimization:
Delete useless code
Abstract repetitive code
Things done by + load method are delayed to initialize, or things done by + load should not take too much time.
Reduce unnecessary framework, or optimize existing framework
Main stage optimization
Delayed execution of code in didFinishLauchingwithOptions
Start the rendered page optimization for the first time
27. Crash protection?
Unrecognized selector crash
KVO crash
NSNotification crash
NSTimer crash
Container crash (array out of bounds, insert nil, etc.)
NSString crash (crash for string manipulation)
Bad Access crash (wild pointer)
UI not on Main Thread Crash (non-main thread UI (mechanism to be improved)
28. Memory leak?
Mainly focus on circular reference issues, such as block, NSTime, perform selector reference counting problems.
29. UI Catton Optimization?
30. Architecture & Design pattern
Introduction to MVC Design pattern
What is the difference between MVVM introduction, MVC and MVVM?
Hot signal and cold signal of ReactiveCocoa
Cache architecture design LRU scheme
SDWebImage source code, how to achieve decoding
AFNetWorking source code analysis
Implementation of componentization and design of middleware
The implementation principle of hash table? How to resolve conflicts
31. Data structure & algorithm
Quick sort, merge sort
Two-dimensional array lookup (each row is sorted incrementally from left to right, and each column is sorted incrementally from top to bottom. Please complete a function, enter such a two-dimensional array and an integer to determine whether the array contains the integer)
Traversal of binary tree: judging the number of layers of binary tree
Single linked list judgment ring
32. Computer Foundation
Http and https? Socket programming? Tcp 、 udp? Get and post?
Tcp three-way handshake and four-way handshake
The difference between process and thread
At this point, the study of "what are the advanced iOS interview questions" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.