IOS interview question summary, ios question Summary
1. Why is Objective-c a Dynamic Language?
1. The types of object-c classes and data variables are determined at runtime rather than during compilation. For example, for polymorphism, we can use the parent class object to point to the subclass object and call the subclass method. For the runtime feature, we can dynamically add or replace methods.
2. What about MVC, MVVM, and MVP?
MVC: logic, attempt, and data are layered to achieve decoupling.
MVVM: Short for Model-View-ViewMode mode. It consists of three parts: View, ViewModel, and Model. the Controller is more bloated than MVC, and some logic (time-consuming, public method, network request, etc.) and data processing operations are carried from the ControllerViewModel
Medium
MVVM features:
- Reusability. You can put some View logic in the ViewModel so that many views can reuse this View logic.
- Independent development. Developers can focus on developing business logic and data (ViewModel ). Designers can focus on the design of interfaces (Views.
- Testability. You can test the interface (View) for the ViewModel.
MVP: I am not in touch with this small editor. I hope I can help you. You can leave a message below.
3. Why does the proxy use weak? What is the difference between the proxy's delegate and dataSource? What is the difference between block and proxy?
The proxy is modified using weak.. 1. weak is used to avoid circular reference. 2. When weak-modified attributes are used and the objects are released, the system assigns a value to the attributes.nil
Object-c has a featurenil
The object sends messages, that is, call methods, without cash.
Delegate: Proxy. The proxy can notify object A of the changes that occur in object B (A). premise B follows the proxy of object A and implements the proxy method of object.
DataSource: Indicates the data source. If object A declares the data source, when we create object A, we should implement the data source to tell A about the data it needs. For example, for the tableView data source method, you need to tell it how many groups of cells I want to implement, how many lines of cells are in each group, how cell style and content are implemented.
Similarlydelegate
AnddataSource
.require
Andoptional
.
Proxy and Block differences
Similarities: Most proxies and blocks can be used for values in reverse order. We need to avoid circular references.
Difference: the proxy uses weak modification. The proxy must declare the method first. When we call a proxy, we need to determine whether it has been implemented.
Block: Use copy to modify the block. block stores a piece of code, which is actually a function. When we call block, we need to determine whether it has been implemented.
4. What is the essence of an attribute? Which parts are included? What are the default Keywords of the attribute? What are the @ dynamic keywords and @ synthesize keywords used?
Attributes are the characteristics of a descriptive class, that is, what features are available. Three parts: underlined member variables, get and setter methods.
Default keywords: readwrite, assign, atomic;
@ Dynamic: modifier attributes. The getter and setter method compilers will not automatically generate them for you. It must be implemented by yourself.
@ Synthesize: modifier attribute. The getter and setter method compilers automatically generate the attributes for you. You do not have to implement it yourself. You can specify the member variables corresponding to the attributes.
5. What is the default keyword of the attribute?
Default keywords: readwrite, assign, atomic;
6. Why should I use the copy keyword for NSString? If strong is used, what is the problem? (Note: If strong is not used, it cannot be used. The use of copy and strong depends on the situation.
As we all know, the variable type (NSMutableArray, NSMutableString, etc.) is a subclass of the non-edge type (NSString, NSArray, etc.). Due to polymorphism, we can use the value assignment to point to the subclass object, that is, we can use the edge type to accept the variable type.
1. when we use strong to modify the non-edge type of A, and assign A value to A using the variable type of B, and then modify the variable type of B, the value pointed to by A will also change. The citation strong only allows the created object to reference counter + 1 and return the content address of the current object. When we modify the content that B points to, the content that A points to also changes,Because they point to the same memory address, it is a copy of the content.
2. when we use copy to modify the non-edge type of A, and use B to assign A value to A, and then modify the value of variable type B, the value pointed to by A will not change. Because when we modified the copy, we copied A copy of the content and returned the pointer to A. When we modified the content pointed to by B, the content that A points to has not changed.Because A points to the memory address and B points to the memory address is not the same, is two content
3. When copy modifies the edge type (NSString, NSArray, etc,And assign values using the non-edge type,It indicates a shortest copy and only one copy of the pointer. It is the same as strong modification. When it is a variable type (NSMutableArray, NSMutableString, etc.), it indicates a deep copy and a new copy of the content is directly copied, to the memory. Indicates two parts.
7. How can I copy the object I wrote?
Must follownscopying
Protocol, if you want to implement mutable and non-edge copy, you must follownscoping
Andnsmutablecoping
Protocol. And implement
-(Id) copyWithZone :( NSZone *) zone;
8. What is the difference between the copy and mutablecopy of a variable collection class and an immutable collection class? If the set is content replication, is the element in the Set also content replication?
The variable uses copy to indicate deep copy, and the non-variable sets use copy to indicate the shortest copy.
Mutablecopy is used by the variable collection class to indicate deep copy, while copy is used by the non-variable collection class.
For container copy or metableCopy, by default, all elements in the container are pointer copies instead of content copies.
9. Why does the UIView modified by IBOutlet also use the weak keyword?
When the xib or Sb Drag Control is used, the control is actually loaded into the subviews array of the parent control and strongly referenced. Even if weak is used, the object is not released.
10. What is the difference between nonatomic and atomic? Is atomic absolutely thread-safe? Why? If not, how should we implement it?
Nonatomic: Non-atomic, unsafe, but efficient.
Atomic: Indicates atomic rows, which are safe but efficient.
Atomic: the thread security cannot be absolutely guaranteed. When multiple threads are simultaneously accessed, thread security may occur. Thread locks can be used to ensure thread security.
11. How does UICollectionView customize layout?
The general practice of implementing a custom layout is to inherit the UICollectionViewLayout class and then reload the following methods:
-(CGSize) collectionViewContentSize returns the size of the collectionView content-(NSArray *) Layout :( CGRect) rect returns the layout attribute of all elements in rect and returns the layout attribute of all elements that contain uicollectionviewlayoutbutes. It can be cell, you can obtain different types of UICollectionViewLayoutAttributes: layoutattributes: layoutAttributesForCellWithIndexPath: layoutAttributesForSupplementaryViewOfKind: wit through different uicollectionviewlayoutbutes initialization methods. HIndexPath: paths: withIndexPath:-(UICollectionViewLayoutAttributes) rows :( NSIndexPath) indexPath returns the layout attribute of the cell corresponding to the location of indexPath-(rows) rows :( NSString) kind atIndexPath :( NSIndexPath *) indexPath returns the layout attribute of the append view corresponding to the position of indexPath. If there is no append view, you can choose not to overload it-(UICollectionViewLayoutAttributes *) layo Constraint :( NSString) decorationViewKind atIndexPath :( NSIndexPath) indexPath returns the layout attribute of the decoration view corresponding to the position of indexPath. If no decoration view is available, you can choose not to overload it-(BOOL) shouldInvalidateLayoutForBoundsChange) whether the la S should be refreshed when the boundaries change. If YES, the layout information is recalculated when the boundary changes (generally scroll to another place.
12. What are the drawbacks of using StoryBoard to Develop interfaces? How to avoid it?
You can use sb to jump to a simple logic page.
However, when the logic project is complex, the development of SB is slow. It is not suitable for collaborative development by many people; it is also not conducive to version stem and later maintenance. When sb is used for project variant compilation, it is also directly loaded into the memory, resulting in a waste of memory.
You can use xib instead. You can use pure code to edit complex logic interfaces.
13. What is the difference between a process and a thread? What is the difference between synchronous and asynchronous? What is the difference between parallelism and concurrency?
Process: A running activity of a program with certain independent functions. A process is an independent unit for the system to allocate and schedule resources.
Thread:It is an entity of a process and the basic unit of CPU scheduling and dispatching. It is smaller than the process and can run independently. the thread itself basically does not have system resources, and only has a few resources (such as program counters, a set of registers and stacks) that are essential for running ), however, it can share all resources of a process with other threads of the same process.
Synchronization:The current thread operation is blocked and the thread cannot be opened up.
Asynchronous:The thread can be opened to execute tasks without interrupting the operation.
Concurrency:When multiple threads are operating, if the system has only one CPU, it is impossible for the system to actually execute more than one thread at the same time. It can only divide the CPU running time into several time periods, then, the time segment is allocated to each thread for execution. When the thread code is running in one time period, other threads are suspended .. This method is called Concurrent ).
Parallelism:When the system has more than one CPU, the thread operations may be non-concurrent. When one CPU executes one thread, the other CPU can execute another thread. The two threads do not compete for CPU resources and can run at the same time. This method is called Parallel ).
Differences:Concurrency and parallelism are two similar and different concepts. parallelism refers to the occurrence of two or more events at the same time; concurrency means that two or more events occur at the same time interval. In a multi-program environment, concurrency means that multiple programs run at the same time within a period of time, but in a single processor system, only one program can be executed at a time, therefore, these programs can only be executed in a time-based manner. If there are multiple processors in the computer system, these programs that can be concurrently executed can be allocated to multiple processors for parallel execution, that is, each processor is used to process a program that can be concurrently executed, so that multiple programs can be executed simultaneously.
14. Inter-thread communication?
When the dispath-async function is used to open up the thread to execute the task, we need to use dispatch_async (dispatch_get_main_queue (), ^ {}); the function will refresh the UI in the main thread. Complete Communication
15. Some common functions of GCD? (Group, barrier, semaphore, thread synchronization)
When we use a queue group to open up threads, the queue tasks in the queue group are concurrent. Only when all the tasks in the queue group are completed can we call the queue group to complete the task.
/** Create your own queue */dispatch_queue_t dispatchQueue = dispatch_queue_create ("ted. queue. next ", Schedule);/** create a queue Group */dispatch_group_t dispatchGroup = dispatch_group_create ();/** Add a queue task to a queue Group */dispatch_group_async (dispatchGroup, dispatchQueue, ^ () {NSLog (@ "dispatch-1") ;});/** Add a queue task to a queue Group */dispatch_group_async (dispatchGroup, dispatchQueue, ^ () {NSLog (@ "dspatch-2") ;});/** queue group completion call function */dispatch_group_notify (dispatchGroup, dispatch_get_main_queue (), ^ () {NSLog (@ "end ");})
Barrier: It indicates a fence. When a fence is used in a concurrent queue, concurrent tasks before the fence start to run concurrently. After the fence is executed, execute the tasks within the fence. After the Fence task is completed, then execute the job after the fence concurrently.
dispatch_queue_t concurrentQueue = dispatch_queue_create("my.concurrent.queue", DISPATCH_QUEUE_CONCURRENT);dispatch_async(concurrentQueue, ^(){ NSLog(@"dispatch-1");});dispatch_async(concurrentQueue, ^(){ NSLog(@"dispatch-2");});dispatch_barrier_async(concurrentQueue, ^(){ NSLog(@"dispatch-barrier"); });dispatch_async(concurrentQueue, ^(){ NSLog(@"dispatch-3");});dispatch_async(concurrentQueue, ^(){ NSLog(@"dispatch-4");});
Semaphores: Semaphore uses the 'Count' method to identify whether the thread is waiting or continues execution. Semaphores
Dispatch_semaphore_create (int) // create a signal, initialize the signal count size/* Wait signal, and determine the semaphore. If the semaphore count is greater than or equal to the semaphore count when you create it, you can continue execution and reduce the incoming signal count by 1. * If the incoming signal count is smaller than the one you created, it indicates waiting, wait for a change in the signal count * If the waiting time exceeds the time you passed in, the following operation will continue * First parameter: semaphore indicates the semaphore * second parameter: indicates the waiting time * return int. If the input signal count is greater than or equal to the count of the signal you created, 0 is returned. otherwise, the returned result is not equal to 0 */int result = dispatch_semaphore_wait (dispatch_semaphore_t semaphore, time outTime); // indicates waiting, it is also a hindrance to the thread. // It indicates the signal technology + 1dispatch_semaphore_signl (dispatch_semaphore_t semaphore );
Thread Synchronization Methods: Serial queue, grouping, and semaphores. Concurrent queues can also be used.
// Add the dispatch_async (concurrentQueue, ^ {// 1. download the image dispatch_sync (concurrentQueue, ^ {}) online first; // 2. display dispatch_sync (dispatch_get_main_queue (), ^ {}) ;}on the main thread interface {});});
16. How can I use a queue to avoid resource snatching?
When we use multiple threads to access the same data, the data may be inaccurate. In this case, I can use the thread lock to bind it. You can also use a serial queue. For example, fmdb uses FMDatabaseQueue to snatch resources through multiple threads.
17. Several solutions for data persistence (fmdb has never been used)
Persistence Solution:
Plist, storage dictionary, array is more useful
Preference: preference settings, essentially plist
NSKeyedArchiver: Archive, which can store objects
Sqlite: Database, which is often operated by a third party, that is, fmdb
CoreData: it is also a database storage, which is officially owned by Apple.
18. How many methods does appdelegate work? What methods have been called from the background to the foreground? What methods are called at the first start? What methods have been called from the foreground to the background?
1029210 (1).gif 19. What are the advantages of NSCache over NSDictionary?
1. nscache can automatically release the memory.
2. nscache is thread-safe. We can add, delete, and query objects in the cache in different threads.
3. A cache object does not copy the key object.
20. Do you know the Designated Initializer? When using it, what do you need to pay attention?
My understanding: initialization function. If you want to customize the initialization function, you must also initialize the parent class to ensure that you can inherit some methods or attributes of the parent class.
Designated Initializer
21. What effect can the description method achieve?
Description is an instance method of nsobject, and an nsstring is returned. When nslog is used for printing, the output is generally the memory address of the object. If we implement the description method, we can use nslog to print the object, we can print out the attribute values and the memory address together.What you print is what you write.
-(NSString *) description {NSString * string = [NSString stringWithFormat: @ "<Person: Memory Address: % p name = % @ age = % ld>", self, self. name, self. age]; return string ;}
22. What mechanism does objc use to manage object memory?
Use the memory management counter to manage the memory. When the memory management counter is 0, the object will be released.
What is the essence of the intermediate Block1.block? How many blocks are there? Under what circumstances?
Block: essentially an object-c object.
Block: storage location, which may be divided into three parts: Code de-partitioning, heap zone, stack zone (in the case of ARC, it will be automatically copied to the heap zone, so there are only two parts under ARC: code removal, heap)
Code Area: Do not access the stack zone variables (such as local variables), and do not access the heap zone variables (the objects created by alloc). At this time, the block is stored in the code.
Heap Area: Access the variables in the stack or heap, and block is stored in the heap. -It should be noted that it is actually placed in the stack area, and will be automatically copied to the heap area in the ARC case. If it is not an ARC, it will be stored in the stack area. After the function is executed, it will be released, if you want to call it outside, you need to use copy to point to it, so that it will be copied to the heap zone. The strong attribute will not be copied and will cause the wild pointer to be in the wrong zone.
2. Why cannot I modify the variables captured by the block by default? _ What has been done by block?
By default, the variables in the block are copied to the value of the variable, rather than the pointer to the memory of the variable.
When using__block
The modified variable is copiedblock
It is the pointer to the variable, so we can modify the value of the variable.
3. simulate a situation of loop reference? How does one implement reverse value transfer on the block implementation interface?
Person *p = [[Person alloc]init];[p setPersonBlock:^(NSString *str) { p.name = str;}];
What happens when Runtime1.objc sends a message to an object?
Based on the object'sisa
Pointer to find Class Objectid
, In the Query Class ObjectmethodLists
Method function list. If notsuperClass
, Find the parent class, and then in the parent classmethodLists
Query in the method list and findSEL
, Accordingid
AndSEL
ConfirmIMP
(Pointer function), sending a message;
3. When will the unrecognized selector error be reported? What mechanisms does iOS have to avoid this step?
When a message is sentmethodLists
List to query what we want to useSEL
When the query fails, we will continue to query along the parent class. When the final query fails, we will reportUnrecognized selector Error
When the system cannot query the method, it will call+(BOOL)resolveInstanceMethod:(SEL)sel
Dynamic Interpretation MethodTo give me a chance to add a method that cannot be called. Or we can use it again.-(id)forwardingTargetForSelector:(SEL)aSelector
Redirection MethodTo tell the system what method to call, so that it will not crash.
4. Can I add instance variables to the compiled class? Can I add instance variables to the class created at runtime? Why?
1. instance variables cannot be added to the compiled class.
2. You can add instance variables to the classes created at runtime.
Explanation:
1. the compiled class has been registered in runtime. The linked list of the objc_ivar_list instance variable in the class structure and the memory size of the instance_size instance variable have been determined. runtime will call class_setvarlayout or class_setWeaklvarLayout to handle strong we. therefore, you cannot add instance variables to an existing class.
2. The class created during the runtime can be used to add instance variables and call the class_addIvar function. However, after objc_allocateClassPair is called and objc_registerClassPair is called, the reason is the same as above.
5. How does runtime implement automatic nil setting of weak variables?
Runtime will layout the registered classes and put the weak objects in a hash table. Use the memory address of the object pointed to by weak as the key. When the reference count of this object is 0, dealloc is triggered. If the memory address of the object pointed to by weak is, search for all weak objects with the key in this weak table and set it to nil.
6. After adding an attribute to the class, what elements will change in the class struct?
Instance_size: memory size of the Instance
Objc_ivar_list * ivars: attribute list
What does RunLoop1.runloop do? What is the relationship between runloop and thread? Does the main thread enable runloop by default? What about the sub-thread?
Runloop: it literally refers to the running circle, which is actually a loop to process events and messages in the thread.
Relationship between runloop and thread: if each thread wants to continue running without being released, it must have a runloop to keep running and process various events and messages in the thread.
By default, the main thread enables a runloop. That is, this runloop can ensure the normal operation of our program. The child thread does not start the runloop by default.
2. What is the runloop mode used? How many modes are there?
Model: it is the mode in runloop. In different modes, the events processed by runloop are different from those of messages.
Five modes are registered by default:
(1) kCFRunLoopDefaultMode: the default Mode of the App. Generally, the main thread runs in this Mode.
(2) UITrackingRunLoopMode: interface tracking Mode, used for ScrollView tracking touch sliding, to ensure that the interface sliding is not affected by other modes.
(3) UIInitializationRunLoopMode: The first Mode that is entered when the App is started. It is no longer used after startup.
(4) GSEventReceiveRunLoopMode: the internal Mode for accepting system events, which is usually unavailable.
(5) kCFRunLoopCommonModes: This is a placeholder Mode and has no practical effect.
Note:IOS encapsulates the model in the above 5
NSDefaultRunLoopMode;
Nsunloopcommonmodes
3. Why does the nstultrobject not move after being added to the main running loop by using NSDefaultRunLoopMode (kCFRunLoopDefaultMode?
The nstime object is inNSDefaultRunLoopMode
The message is called below, but when we slide scrollview,NSDefaultRunLoopMode
Mode is automatically switchedUITrackingRunLoopMode
But cannot continue to respond to messages sent by nstime. So if you want to call the nstime message while sliding the scrollview, we can change the mode of nsunloopNSRunLoopCommonModes
4. How does apple implement Autorelease Pool?
Autorelease Pool function: cache Pool, which can avoid frequent relase writing. In fact, it is the delayed release, which adds the created object to the latest autoreleasePool. When the scope of autoreleasePool ends, the Reference Counter of all objects in it is-1.
Autorelease
Class Structure 1. isa pointer? (The isa of the object, the isa of the class object, and the isa of the Meta class must be said)
In oc, classes are also objects and belong to the metadata class. So it is often said:All objects
The isa pointer of the object points to the class to which it belongs.
The isa pointer of the class points to its Meta class.
Isa of the Meta class points to the root Meta class, and the root Meta class points to itself.
AC17D0A0-CB2A-4C23-8430-4BC7A99571CE.png2. What is the difference between a class method and an instance method?
Different calling methods must be called by class methods. Attributes cannot be called in methods, and class methods must also be called in class methods. Stored in the meta-class structmethodLists
Inside
The instance method must be called by an instance object. You can use attributes in the instance method, and the instance method must also be called. Stored in the class structmethodLists
Inside
3. What can I do with classification? How is it implemented internally? Why does it overwrite the original method?
Category: You can add an instance method to a class or system class. The instance method we added will be dynamically added to the class structuremethodList
List. Categort
4. Can I add member variables during running? Can attributes be added? If yes, how can I increase it? If not, why?
Attribute can be added, but we must implement itsgetter
Andsetter
Method. But the same name of the strip is not added.Member variables
But we useruntime
The method for adding member variables is as follows:
-(Void) setName :( NSString *) name {/*** associates an object with a class ** @ param object #> description #> * @ param key #> attribute key description to be associated #> * @ param value #> description #> * @ param policy #> modifier of the added member variable #> */objc_setAssociatedObject (self, @ selector (name), name, OBJC_ASSOCIATION_COPY_NONATOMIC);}-(NSString *) name {/*** get an associated object of a class ** @ param object #> description of the associated object #> * @ param key #> attribute key value description #> */return objc_getAssociatedObject (self, @ selector (name ));}
5. What will happen when a message is sent to an nil object in objc? (The return value is an object, a scalar, a struct)
• If a method returns an object, the message sent to nil returns 0 (nil ). For example: Person * motherInlaw = [aPerson spouse] mother]; if the spouse object is nil, the message mother sent to nil will also return nil.
• If the return value of a method is of the pointer type, the pointer size is an integer scalar that is smaller than or equal to sizeof (void *), float, double, long double, or long, the message sent to nil will return 0.
• If the return value of a method is a struct, as in the Mac OS X ABI function call guide, the message sent to nil will return 0. The values of each field in the struct will be 0. Other struct data types are not filled with 0.
• If the return value of the method is not in the preceding situations, the return value of the message sent to nil is undefined.
Answers
Advanced 1. UITableview optimization method (Cache height, asynchronous rendering, reduced level, hide, avoid off-screen rendering)
Cache Height: When we create a frame model and calculate the height of the cell, we can cache the height of the cell into the dictionary, using the cell'sindexpath
AndIdentifier
As the key.
NSString *key = [[HeightCache shareHeightCache] makeKeyWithIdentifier:@"YwywProductGradeCell" indexPath:indexPath];if ([[HeightCache shareHeightCache] existInCacheByKey:key]) { return [[HeightCache shareHeightCache] heightFromCacheWithKey:key];}else{ YwywProductGradeModelFrame *modelFrame = self.gradeArray[indexPath.row]; [[HeightCache shareHeightCache] cacheHieght:modelFrame.cellHight key:key]; return modelFrame.cellHight;}
Asynchronously draw and reduce layers: It is not clear yet
Hide: Personal understanding should behidden
Create all the controls that may be used and hide or display them according to different situations.
Avoid off-screen Rendering: As long as it is not used at the same timeBorder/border color and rounded corner
, You can use the layer to directly set. Does not cause off-screen rendering.
2. Is there anything that can be done with a runtime? (Exchange methods, create classes, add methods to newly created classes, and change the isa pointer)
Exchange mode: generally written in the + (void) load Method of the class
/** Obtain the original setBackgroundColor Method */Method originalM = class_getInstanceMethod ([self class], @ selector (setBackgroundColor :)); /** obtain the custom pb_setBackgroundColor Method */Method exchangeM = equals ([self class], @ selector (pb_setBackgroundColor :));/** exchange Method */method_exchangeImplementations (originalM, exchangeM );
Creation class:
Class MyClass = objc_allocateClassPair([NSObject class], "Person", 0);
Add Method
/** Parameter 1, class name parameter 2, method name parameter added by SEL 3. IMP pointer (IMP stands for Implementation and it points to a method Implementation pointer, each method has a corresponding IMP) parameter 4, where the types parameter is "I @: @", expressed in order: the specific type can refer to [official documentation] (https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html) I return value type int. If it is v, void @ parameter id (self): SEL (_ cmd) @ id (str) V @: the return value is void with the SEL parameter (An object (whether statically typed or typed id) */class_addMethod (Person, @ selector (addMethodForMyClass :), (IMP) addMethodForMyClass, "V @: ");
Add instance variables
/** Parameter 1, class name parameter 2, attribute name parameter 3, open byte length parameter 4, method parameter 5, parameter type "@" official explanation of An object (whether statically typed or typed id) (object static type or id type) specific types can refer to the [official documentation] (https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html) return: whether BOOL is added successfully */BOOL isSuccess = class_addIvar (Person, "name ", sizeof (NSString *), 0, "@"); isSuccess? NSLog (@ "variable added successfully"): NSLog (@ "failed to add variable ");
3. What third-party framework source code have you seen? How is it implemented? (If not, ask about the design of multi-image download.) 4. What is the cache policy of SDWebImage?
When sd loads an image, it first searches for whether the image exists in the memory. If it does not, it will search for the image in the sandbox Based on the md5 (url) Name, whether this image exists. If it does not exist, a thread will be opened for download. After the download is complete, it will be loaded to the imageview and the md (url) name will be cached in the sandbox.
5. Why does AFN Add a resident thread?
AFN aims to open up a thread to request network data. If there is no resident thread, the thread will be opened every time the network is requested, and the thread will be destroyed after completion, which will lead to a waste of resources. Opening a resident thread will avoid this waste, we can add each network request to this thread.
6. How to Use KVO? Implementation principle? (Why do we need to create a subclass for implementation)
Kvo: Observe the key value and call the method based on the changes in the key value.
Register the observer: addObserver: forKeyPath: options: context:
Implemented observer: observeValueForKeyPath: ofObject: change: context:
Remove observer: removeObserver: forKeyPath :( object destruction, the observer must be removed)
Note:
When using kvo to listen to object A, the essence of the listener is not this object A, but an intermediate object created by the system.NSKVONotifying_A
And inherit from object A, and the isa pointer of object A is not A class, but thisNSKVONotifying_A
Object
Kvo details
Kvo details 2
7. How to Use KVC? Implementation principle? (How do KVC assign values after getting the key? Do you know whether the set operator can access private attributes or _ ivar directly)
Kvc: key value assignment, the most used even if the dictionary is used for model conversion. Use runtime to obtain all the member variables of an object. assign values based on the kvc key value to convert the dictionary into a model.
SetValue: forKey: Only search for attributes in this class
SetValue: forKeyPath: searches for attributes in the class, and does not search for attributes in the parent class.
Kvc details
Project 1. Is there any online project? 2. Which part of the project did you complete? (Find a highlight and ask how to implement it) 3. What difficulties have you encountered during development and how have you solved them? 4. How can I help myself understand a problem that cannot be understood at all? For example? 5. Do you have the habit of reading books? What kind of books have you read recently? What are your experiences? 6. Are Some Notes software used? Will it be synchronized on multiple platforms and collected through multiple channels? (If not, ask how to review the knowledge) 7. Is there any software for the configuration class and calendar class used? (If not, ask how to arrange and plan tasks.) 8. Do you usually read a blog? Have you ever written it yourself? (What are the gains from writing? If not, ask the reason for not writing)
The above are all interview questions. The interview questions below should be answered according to your own situation.
Some of the above interview answers are based on your knowledge reserves, and some are also made up by Baidu.
You are welcome to express your opinion on the correct and wrong answers.
Author: fish with 7-second memory
Link: http://www.jianshu.com/p/f9eb6b315c08
Source: Simplified book
Copyright belongs to the author. For commercial reprint, please contact the author for authorization. For non-commercial reprint, please indicate the source.