<span id="Label3"></p>All the interview questions in this article are from interview Bat's seniors or classmates to give me a record, I will list and give answers, on the one hand as notes, on the other hand for the benefit of everyone <blockquote> <blockquote> <p>iOS Network layer Design</p> </blockquote> </blockquote><p><p><strong>1, Network layer and business layer of docking design</strong></p></p> <ul> <ul> <li><p>Which interaction mode to use to interface with the business layer: the use of delegate-based, the purpose is to <strong>(1)</strong> reduce the dispersion of the code <strong>(2)</strong> reduce the business layer and network layer coupling, the network layer for the business layer should be abstract, hiding the implementation details <strong>(3) </strong>only one is limited flexibility and facilitates maintenance</p></li> <li><p>Do not misuse The block at the network Level:<strong>(1)</strong>block will prolong the lifetime of the object, delegate will not<br><strong>(2)</strong>block suitable for each callback task is different, if the same should be used delegate, apple Internal Network layer package is delegate (discrete type), AF Network layer encapsulated as block (intensive Type)</p></li> <li><p>Use a Reformer object to encapsulate the data conversion logic, thus saving the business layer of the dictionary to model such a cumbersome operation, and in order to solve the problem of the readability of the direct use of the dictionary, using a const variable such as kpropertystudentid as the key of the Dictionary.</p></li> <li><p>Using a discrete (delegate) approach to Network layer encapsulation requires inheritance, using a Baseapimanager as the parent class to handle all operations that require intensification (for example, some common information), and then let many subclasses do discretization operations</p></li> </ul> </ul><p><p><strong>2, Network layer of security protection</strong></p></p> <ul> <ul> <li><p>To prevent competitors from using their own api, design a signature for their own api, the server gives a key, each time using the API to do a hash algorithm operation, the hash value and the server hash out the value of a comparison, if the same, it indicates that they are using the API</p></li> <li><p>Prevent man-in-the-middle attacks and use a more secure HTTPS protocol to prevent operators from adding ads to their requests</p></li> </ul> </ul> <blockquote> <blockquote> <p>The difference between the MVC pattern and the MVVM pattern</p> </blockquote> </blockquote><p><p><strong>1. The MVC pattern has the problem of code bloat in controller</strong><br>The MVC pattern arises because there is a lot of code that can be reused in development, and That's exactly the case, and the MVC three without model and view code can really be reused because of the MVC pattern, and there are many open source projects on GitHub that encapsulate a lot of view , we can easily use these View,model classes as a class of data conversion logic can also be reused in the same project, but the controller is difficult to reuse in a project, So when we write code, we try to write only those code that can't be reused in the controller, such as adding the view to the controller, passing the model data to the view, etc., but it's really hard to do it, and there's always a lot of code that we don't know where to put, In the end it was placed in the controller, causing the controller to become very bloated.</p></p><p><p><strong>2, the controller in the MVC mode to thin body</strong><br>We can thin the controller from the following points:</p></p> <ul> <ul> <li>Extract the code from the view to the controller to the custom UIView to encapsulate</li> <li>Extracting network requests for encapsulation</li> <li>Data acquisition and data conversion logic extracted for encapsulation</li> <li>Constructs a viewmodel in the MVVM pattern, which encapsulates the conversion logic of the data</li> </ul> </ul><p><p><strong>3. The cognition of the MVVM pattern</strong></p></p> <ul> <ul> <li>The MVVM pattern has two-way binding technology, that is, ViewModel changes, then the model changes</li> <li>Bidirectional binding can make it difficult to find where a bug appears</li> <li>Two-way binding in large projects can cause memory consumption to be excessive</li> </ul> </ul><p><p><strong>4. Summary</strong><br>Instead of blindly pursuing new technologies, or being overly conservative and unwilling to move forward, it should be combined with the strengths of MVC and MVVM to make controllers Lean.</p></p> <blockquote> <blockquote> <p>How to set rounded corners in iOS</p> </blockquote> </blockquote><p><p><strong>1, The general mode of installation of the performance of the loss</strong><br>Setting fillets with the Cornerradius property does not produce off-screen rendering and does not actually produce rounded corners on the ui, so we need to set maskstobounds to Yes to produce rounded corners on the ui, but at the same time, this also results in off-screen rendering. Generating off-screen rendering is a significant performance drain and will degrade FPS frames because the off-screen rendering requires processing of the image in a memory buffer outside the screen, and the resulting image is placed on the home screen after processing is Finished. In this process, the maximum consumption is two context interaction, which will be processed to the buffer outside the screen, and then the resulting image is placed on the home Screen.</p></p><p><p><strong>2. Create rounded corners using a method that does not produce off-screen rendering</strong><br>Use Bezier Uibezierpath and the core graphics frame to draw a fillet</p></p><pre><pre><code class="objc">UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; imageView.image = [UIImage imageNamed:@"1"]; //开始对imageView进行画图 UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, [UIScreen mainScreen].scale); //使用贝塞尔曲线画出一个圆形图 [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width] addClip];[imageView drawRect:imageView.bounds];imageView.image = UIGraphicsGetImageFromCurrentImageContext(); //结束画图UIGraphicsEndImageContext();[self.view addSubview:imageView];</code></pre></pre><p><p><strong>3. Summary</strong></p></p> <ul> <ul> <li>If you don't have a lot of rounded corners on your screen, you can set it up in the usual way</li> <li>If a large number of fillets are present on the screen, the rounded corners need to be optimized to prevent off-screen rendering</li> </ul> </ul> <blockquote> <blockquote> <p>Click on the avatar to enlarge the animation idea</p> </blockquote> </blockquote><p><p>Create a background and a new Uiimageview,uiimageview is located above the background, first change the background transparency to 0, then animate, The effect of the animation is to change the new Uiimageview from the original position (this position is the original Uiimageview on the new background frame) to the magnified position, then listen to the background of the click event, click on the time of the transparency and frame of the opposite changes can Be. The specific process I've encapsulated and uploaded to github, click here to View.</p></p> <blockquote> <blockquote> <p>How to fix bugs on online projects</p> </blockquote> </blockquote><p><p>This will involve the use of the Jspatch framework, the role of which is to heat fix bugs. Subsequent updates</p></p> <blockquote> <blockquote> <p>What's going to happen in iOS development with circular references</p> </blockquote> </blockquote><p><p><strong>1. block</strong><br><strong>2, delegate</strong><br><strong>3, Nstimer</strong><br>Workaround: use a nstimer catagory, and then rewrite the initialization method, using block in the implementation, so that you can use the weakself to perform a task in the block at the time of the call</p></p> <blockquote> <blockquote> <p>When will the Autoreleasepool (object added to Autoreleasepool) be released?</p> </blockquote> </blockquote><br>Runloop and Autoreleasepool <ul> <ul> <li>Create Autoreleasepool when Runloop is started</li> <li>Destroy Autoreleasepool at the end of the Runloop.</li> <li>When Runloop sleeps, it will destroy the previous Autoreasepool and create a new Autoreleasepool</li> </ul> </ul> <blockquote> <blockquote> <p>Depth copy in iOS</p> </blockquote> </blockquote><p><p>Check out this article for a deep dive: iOS anatomy depth copy</p></p> <blockquote> <blockquote> <p>Property modifiers in iOS</p> </blockquote> </blockquote><p><p>The order of the descriptors is the order of the modifiers at the time of Declaration.</p></p><p><p><strong>1. Atomic modifier</strong></p></p> <ul> <ul> <li>Nonatomic: The properties are generally decorated with nonatomic, and if you need to ensure thread safety, manually add code to protect</li> <li>Atomic: The default is atomic, using this modifier, the system will be atomic protection of properties, to ensure thread safety, but there will be performance loss</li> </ul> </ul><p><p><strong>2. Read-write permission modifier</strong></p></p> <ul> <ul> <li>Readonly: read-only</li> <li>Readwrite: default is ReadWrite decoration</li> </ul> </ul><p><p><strong>3. Memory Management modifier</strong></p></p> <ul> <ul> <li>Strong: strong references, with any strong type of pointer pointing to the object, will not be destroyed by the arc</li> <li>Copy: mainly used for nsstring, nsarray, nsdictionary, and block, the former because they all have mutable type, the latter is because in mrc, using copy can copy block from the stack to the heap area, Using the strong and copy effects in arc, but writing on copy seems to remind us at the moment that the compiler helped us with the copy Operation.</li> <li>Weak: Weak reference: indicates that a non-owning relationship is defined, and if the object pointed to by the property is destroyed, the property value is also emptied, set to the nil pointer</li> <li>Assign: for basic data type decoration, only the assignment operation will be performed simply</li> <li>Unsafe_unretained: composed of unsafe and unretained, unretained and weak similar, unsafe means that he is unsafe, may cause the presence of wild pointers, resulting in crash</li> <li>Strong and Weak,retain effects and strong equivalents are introduced in Retain:arc</li> </ul> </ul><p><p><strong>4. Read-write Method Name modifier</strong></p></p> <ul> <ul> <li>Setter: Modify the name of the setter method</li> <li>Getter: Modify the name of the Getter method</li> </ul> </ul> <blockquote> <blockquote> <p>Those CP in the Properties memory management modifier in iOS</p> </blockquote> </blockquote> <ul> <li><li><p><strong>Strong</strong> vs <strong>copy</strong></p><pre><code class="objc">self.name = anotherName;</code></pre><p>For example, the above code, Using strong, the two pointers to Self.name and Anothername point to an object at the same time that the Self.name points to the object that the Anothername points to, and if you use copy, the Self.name and Anothername pointers both refer to the To a different object, the process is that copy copies the object that Anothername points to (a shallow copy) and then lets Self.name point to the copied Object.</p></li></li> <li><li><p><strong>Strong</strong> vs <strong>weak</strong><br>As long as a property (pointer) with the strong type modifier points to an object, the object is not destroyed by the arc, but the property (pointer) that is decorated with the weak type points to an object, and if the object is destroyed, the property (pointer) is automatically set to Nil. It can be said that the weak type of pointer is not constrained, but simply weakly weakly to represent the Relationship.<br><strong>It is also necessary to analyze whether the control should use strong or weak in the Declaration.</strong></p> <ul> <li><p>If you are using storyboard:</p><br>Storyboard Reference Graphs</li> <li><p>If you are using pure code:</p><br>Pure Code Reference diagram</li> <li><p>In summary, you should use weak to declare the control, in pure code if you use strong to declare the control, then there is a case: if you remove the control, then the controller in the view of the subviews in the reference line will be cut off, however, the line referenced by the strong property (pointer) still exists, and because a strong reference is used, the control will not be destroyed by the arc, so it will always occupy memory until the controller destroys it.</p></li> </ul></li></li> <li><li><p><strong>Weak</strong> vs <strong>assign</strong><br>Weak can only be used for object types, assign is available for basic types, weak is a bit better than assign, and if the Weak-modified property points to an object that is destroyed, then this property will automatically be set to the nil pointer, If an object that is pointed to by the Assign property is destroyed, the property is not automatically set to nil, and he does not know that the object being pointed to has been destroyed, which raises the wild pointer.</p></li></li> <li><li><p><strong>weak</strong> vs <strong>unsafe_unretained</strong><br>If the weak decorated property points to an object that is destroyed, then this property will automatically be set to the nil pointer, and if the unsafe_unretained decorated property points to an object that is destroyed, then this property will not be automatically set to nil, He did not know that the object he was pointing to had been destroyed, thus triggering a wild pointer.</p></li></li> <li><li><p><strong>Assign</strong> vs <strong>unsafe_unretained</strong><br>Assign can modify the base type, unsafe_unretained can only modify the object type</p></li></li> </ul> <blockquote> <blockquote> <p>Multi-threaded in iOS</p> </blockquote> </blockquote><p><p><strong>1, pthread</strong><br>Based on C language, not commonly used<br><strong>2, Nsthread</strong><br>Need to manage the life cycle of the thread on its own, occasionally using, for example, getting the current thread</p></p><pre><pre><code class="objc">[NSThread currentThread];</code></pre></pre><p><p><strong>3. GCD (Grand Central Dispatch)</strong><br>GCD is a multi-core programming solution developed by apple, although it is based on the C language, but it is also very convenient and very important to use block for encapsulation, It is also highly recommended to use GCD for multithreaded programming.<br><strong>4, nsoperation</strong><br>It's Apple's package for gcd, less efficient than GCD.</p></p> <blockquote> <blockquote> <p>GCD in iOS</p> </blockquote> </blockquote> <ul> <ul> <li>General use</li> </ul> </ul><p><p>home <strong>column</strong> : is a special serial queue that runs in the main thread and is used to refresh the ui, which is a serial queue</p></p><pre><pre><code class="objc">//串行队列dispatch_queue_t queue = dispatch_get_main_queue;</code></pre></pre><p><p><strong>Custom Create Queue</strong> : You can either create a serial queue or create a parallel queue.</p></p><pre><pre><code class="objc">//串行队列dispatch_queue_t queue = dispatch_queue_create("nineteen", NULL);dispatch_queue_t queue = dispatch_queue_create("nineteen", DISPATCH_QUEUE_SERIAL);//并行队列dispatch_queue_t queue = dispatch_queue_create("nineteen", DISPATCH_QUEUE_CONCURRENT);</code></pre></pre><p><p><strong>Global parallel Queues</strong> : system-provided parallel queues</p></p><pre><pre><code class="objc">//并行队列dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);</code></pre></pre> <ul> <ul> <li>Other uses</li> </ul> </ul><p><p><strong>Loop Execution Task</strong> : Dispatch_apply is similar to a for loop and executes each item <strong>concurrently</strong> . Dispatch_apply will not return until all tasks have been completed, blocking the current thread (similar to synchronous execution).</p></p><pre><pre><code class="objc"> dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);/* *count: 循环执行次数 *queue: 队列,可以是串行队列或者是并行队列(使用串行队列可能导致死锁) *block: 任务 */dispatch_apply(count, queue, ^(size_t i) { NSLog(@"%zu %@", i, [NSThread currentThread]); });</code></pre></pre><p><p><strong>Queue groups</strong> : Queue groups Add many queues to a group, and when all the tasks in the group are executed, it notifies us by a method. The basic process is to create a queue group first, then add the task to the group, and finally wait for the queue Group's execution Results.</p></p><pre><pre><code class="objc">//创建队列组 dispatch_group_t group = dispatch_group_create(); //创建队列 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //并行队列执行3次循环 (队列组只能用异步方法执行)dispatch_group_async(group, queue, ^{ for (NSInteger i = 0; i < 3; i++) { NSLog(@"group-01 - %@", [NSThread currentThread]); } });//主队列执行5次循环 dispatch_group_async(group, dispatch_get_main_queue(), ^{ for (NSInteger i = 0; i < 5; i++) { NSLog(@"group-02 - %@", [NSThread currentThread]); } }); //都完成后会自动通知 dispatch_group_notify(group, dispatch_get_main_queue(), ^{ NSLog(@"完成 - %@", [NSThread currentThread]); });</code></pre></pre><p><p><strong>Implementing a singleton pattern</strong></p></p><pre><pre><code class="objc">static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ //dispatch_once中的代码只执行一次,常用来实现单例 });</code></pre></pre><p><p><strong>GCD delay operation</strong></p></p><pre><pre><code class="objc">//创建队列dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);//设置延时,单位秒double delay = 3; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), queue, ^{ //3秒后需要执行的任务});</code></pre></pre> <blockquote> <blockquote> <p>Deadlock Scenarios in GCD</p> </blockquote> </blockquote><p><p>Five cases learn about Gcd's deadlock<br>1.<br>Case:</p></p><pre><pre><code class="objc">NSLog(@"1"); // 任务1dispatch_sync(dispatch_get_main_queue(), ^{ NSLog(@"2"); // 任务2});NSLog(@"3"); // 任务3</code></pre></pre><p><p>Results:</p></p><pre><pre><code class="objc">1</code></pre></pre><p><p>2.<br>Case:</p></p><pre><pre><code class="objc">NSLog(@"1"); // 任务1dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSLog(@"2"); // 任务2});NSLog(@"3"); // 任务3</code></pre></pre><p><p>Results:</p></p><pre><pre><code class="objc">123</code></pre></pre><p><p>3.<br>Case:</p></p><pre><pre><code class="objc">dispatch_queue_t queue = dispatch_queue_create("com.demo.serialQueue", DISPATCH_QUEUE_SERIAL);NSLog(@"1"); // 任务1dispatch_async(queue, ^{ NSLog(@"2"); // 任务2 dispatch_sync(queue, ^{ NSLog(@"3"); // 任务3 }); NSLog(@"4"); // 任务4});NSLog(@"5"); // 任务5</code></pre></pre><p><p>Results:</p></p><pre><pre><code class="objc">152// 5和2的顺序不一定</code></pre></pre><p><p>4.<br>Case:</p></p><pre><pre><code class="objc">NSLog(@"1"); // 任务1dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSLog(@"2"); // 任务2 dispatch_sync(dispatch_get_main_queue(), ^{ NSLog(@"3"); // 任务3 }); NSLog(@"4"); // 任务4});NSLog(@"5"); // 任务5</code></pre></pre><p><p>Results:</p></p><pre><pre><code class="objc">12534// 5和2的顺序不一定</code></pre></pre><p><p>5.<br>Case:</p></p><pre><pre><code class="objc">dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSLog(@"1"); // 任务1 dispatch_sync(dispatch_get_main_queue(), ^{ NSLog(@"2"); // 任务2 }); NSLog(@"3"); // 任务3});NSLog(@"4"); // 任务4while (1) {}NSLog(@"5"); // 任务5</code></pre></pre><p><p>Results:</p></p><pre><pre><code class="objc">14// 1和4的顺序不一定</code></pre></pre> <blockquote> <blockquote> <p>Recursive locks in iOS</p> </blockquote> </blockquote><p><p>If the lock operation is in a loop or recursion, the first time the locking has not been unlocked, the second lock is made, so the deadlock phenomenon, this time should use a recursive lock to prevent the occurrence of deadlocks.</p></p> <blockquote> <blockquote> <p>How arc in iOS solves memory management problems</p> </blockquote> </blockquote><p><p>ARC automatically handles the Object's declaration cycle, and when compiled, inserts memory management code where appropriate</p></p> <blockquote> <blockquote> <p>Usage scenarios for autorelease in Arc</p> </blockquote> </blockquote> <ul> <ul> <li>When the function returns an object: the function object should be destroyed as the return value is scoped, but it may not be assigned (strongly referenced), so the object needs to be added to the auto-release pool to prolong the life cycle.</li> <li>When _weak modifies a property: the object pointed to by the _weak property may not have a strong reference to refer to him, it may be destroyed, it is necessary to use the Autorelease method to ensure that he is not destroyed</li> <li>Pointer to ID or pointer to an object</li> </ul> </ul> <blockquote> <blockquote> <p>Runloop in iOS</p> </blockquote> </blockquote><p><p>The general main thread will automatically run runloop, we will not normally go to the Tube. In other sub-threads, if necessary we need to manage. After using runloop, the thread can be imagined into a loop, and if there is no loop, the thread ends when the child thread finishes the Task. So if you need a thread to handle a variety of events without letting it end, you need to run Runloop.</p></p> <blockquote> <blockquote> <p>How does sdwebimage use the runloop?</p> </blockquote> </blockquote><pre><pre><code class="objc">- (void)start{ ... self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO]; ... if(self.connection){ ... CFRunLoopRun( ) ... }}</code></pre></pre><pre><pre><code class="objc">- (void)cancelInternalAndStop { if (self.isFinished) return; [self cancelInternal]; CFRunLoopStop(CFRunLoopGetCurrent());}</code></pre></pre><p><p>After the successful creation of the self.connection, Cfrunlooprun () was executed and Runloop was turned On. The Cfrunloopstop stop Runloop is called when failed or Finished. If Runloop is not turned on, the task is completed after start () and the nsurlconnection agent will not Execute. The Runloop is equivalent to the loop of a child thread, with the flexibility to control the child Thread's life Cycle.</p></p> <blockquote> <blockquote> <p>How does afnetworking use the runloop?</p> </blockquote> </blockquote><p><p>Afnetworking solves this problem by using a different approach: a global thread, a single runloop, and all connection initiated by this runloop, and callbacks are also received by it. This is a good idea, not to occupy the main thread, and not consume CPU resources:</p></p> <blockquote> <blockquote> <p>Response chain in iOS</p> </blockquote> </blockquote> <ul> <ul> <li>Take a look at the incident response with a diagram from an official document<br>Two ways, because the settings are different, but the approximate process is the same</li> </ul> </ul><br>Incident response <ul> <ul> <li>The specific response process <ol> <li>After a touch event occurs, the event is added to a queue managed by the UIApplication</li> <li>UIApplication takes the first event from the queue and then passes the event in roughly the order of <strong>uiapplication->appdelegate->uiwindow-> Uiviewcontroller->superview->subviews</strong></li> <li>Generally speaking, uiapplication will give the event to Keywindow to handle, Keywindow will find a most appropriate view to handle the event, the first step of processing starts here</li> <li>Keywindow is the way to find the right view: call the <strong>hittest:withevent</strong> method to find a view that can handle the touch event,<strong>hittest:withevent</strong> The method recursively checks that the view and the sub-class of the view contain a touch point, like this, always recursively, to find a view that contains the touch point recently, and then pass the touch event to the VIEW. In this process, the <strong>pointinside:withevent:</strong> method is used to determine if the touch point is included, if it contains, return yes, if not included, return no, then <strong>hittest:withevent</strong> This method returns nil, and the View's child view is no longer judged.</li> </ol></li> </ul> </ul> <blockquote> <blockquote> <p>nsrunloop, runloop, autoreleasepool, Thread</p> </blockquote> </blockquote> <ul> <ul> <li><p><strong>nsrunloop</strong>: Nsrunloop is a message loop that detects the input element and timing source and then does callback Processing. Nsrunloop encapsulates the processing of messages in windows, encapsulating details such as sendmessage, PostMessage, getmessage, and so On. About Nsrunloop need to focus on these points:</p> <ol> <li>Nsrunloop is used to listen for time-consuming asynchronous events, such as network callbacks</li> <li>Nsrunloop solves the problem of CPU idling, and when no events need to be processed, Nsrunloop will adjust the thread to hibernate, thus eliminating the Cpu's cycle polling.</li> <li>Each thread has a nsrunloop, the main thread is run by default, the other threads are not running by default, an event needs to be added to nsrunloop, and then the runloop of the thread is Started.</li> </ol></li> <li><p><strong>runloop</strong>: New iOS project will be seen in the main method will be manually created a autoreleasepool, The program is created at the beginning, the end of the destruction, if only on the surface, then this and memory leaks is no different. In fact, for each runloop, the system implicitly creates a autoreleasepool so that all autoreleasepool constitute a stacked structure, at the end of each runloop, The Autoreleasepool at the top of the current stack is ejected and destroyed, and all objects in it are destroyed as Well. The runloop referred to here is not nsrunloop, where runloop can be a UI event, a timer, and so on, specifically referring to a complete process from receiving the message to finishing the Message.</p></li> <li><p><strong>Autoreleasepool and Thread</strong>:<br>Thread is not automatically created for Autoreleasepool</p></li> </ul> </ul> <blockquote> <blockquote> <p>The role of DrawRect</p> </blockquote> </blockquote> <ul> <ul> <li>The purpose of the DrawRect method is to draw the uiview, and to write the specific contents of the drawing in the DrawRect method when Used.</li> <li>Apple does not recommend using the DrawRect method directly, but instead calls the Setneedsdisplay method, and the system then automatically calls DrawRect for UIView drawing</li> </ul> </ul> <blockquote> <blockquote> <p>The role of Layoutsubviews</p> </blockquote> </blockquote> <ul> <ul> <li>The role of Layoutsubviews is to re-layout the child view</li> <li>Apple does not recommend using this method directly, but by calling Setlayoutsubviews to let the system automatically call the Layoutsubviews method for layout</li> <li>Here is a list of when to start the Layoutsubviews method <ol> <li>Call Setlayoutsubviews directly. (this is stated in the official Apple document Above)</li> <li>Addsubview of the Time.</li> <li>When the frame of view Changes.</li> <li>When you slide the UISCROLLVIEW.</li> <li>Rotating screen triggers the Layoutsubviews event on the parent Uiview.</li> <li>Changing the size of a uiview also triggers the Layoutsubviews event on the parent Uiview.</li> </ol></li> </ul> </ul> <blockquote> <blockquote> <p>Custom controls</p> </blockquote> </blockquote> <ul> <ul> <li>There are two types of custom controls, one through Xib and the other by pure code</li> <li>Custom controls need to be rewritten in two ways to achieve the Developer's desired effect <ol> <li>Initwithframe: in general, This method is overridden instead of the Init method, because the Init method eventually calls to the initWithFrame method, This method is primarily a set of initialization settings for controls and child controls of the control (overriding the Awakfromnib method if passed Xib)</li> <li>Layoutsubviews: This method is to describe how a child control is laid out, that is, to give the child control a position in the custom control, so that the setting code for the child Control's frame should not be placed in Initwithframe. It should be in the Layoutsubviews method.</li> </ol></li> </ul> </ul> <blockquote> <blockquote> <p>Comparison of several ways to persist data</p> </blockquote> </blockquote> <ul> <ul> <li><p><strong>plist file</strong> (attribute list):<br>plist files are certain classes that are stored in the directory by means of XML files, including (if there is a corresponding mutable class also includes mutable classes)<br>Nsarray<br>Nsdictionary<br>NSData<br>NSString<br>NSNumber<br>NSDate</p></li> <li><p><strong>Preference</strong>(preferences):</p> <ol> <li>Preferences are specifically used to save configuration information for an Application.</li> <li>If the Synchronize method is not called, the system will be saved to the file in an indefinite time, depending on the I/O Situation. So if you need to write the file immediately, you must call the Synchronize Method.</li> <li>Preferences will save all the data in the same file. A plist file that is named under this application package name in the preference Directory.</li> </ol></li> <li><p><strong>Nskeyedarchiver</strong>(archive):<br><strong>archiving</strong> is another form of serialization in ios, as long as objects that follow the Nscoding protocol can be serialized</p></li> <li><strong>SQLite 3</strong>:<br>All previous storage methods are overwrite Storage. If you want to add a piece of data, you must read the entire file, then modify the data before overwriting the entire content to the File. So they are not suitable for storing large amounts of content, while SQLite 3 is better at reading and writing large amounts of content.</li> <li><strong>CoreData</strong>:<br>Apple-encapsulated local database, typically used to plan for objects in your app</li> </ul> </ul> <blockquote> <blockquote> <p>Status of the app</p> </blockquote> </blockquote> <ul> <ul> <li>Not Running:app is not running yet</li> <li>Inactive:app running on foreground but not receiving events</li> <li>Active:app running in foreground and receiving events</li> <li>Background: running in Background and executing code</li> <li>Suspended: running in background but no code execution</li> </ul> </ul> <blockquote> <blockquote> <p>The difference between UIView and Calayer</p> </blockquote> </blockquote> <ul> <ul> <li>UIView can respond to events, but Calayer Can't.</li> <li>A layer frame is determined by its anchorpoint,position,bounds, and transform, and a view frame is simply a frame that returns to the layer, and the same view center And bounds are also some properties that return Layer.</li> <li>UIView mainly focuses on the management of the display content and Calayer mainly focus on the rendering of the display Content.</li> <li>When doing IOS animations, modifying Non-rootlayer properties (such as position, background color, and so On) will default to an implicit animation, while modifying UIView will Not.</li> </ul> </ul> <blockquote> <blockquote> <p>The realization principle of KVO</p> </blockquote> </blockquote> <ul> <ul> <ul> <li>What is Kvo:<br>KVO provides a mechanism for specifying an object to be observed (for example, a), and when a property of an object (such as the string name in A) changes, the object is notified and processed accordingly</li> <li>The principle of kvo: <ol> <li><strong>nskvonotifying_a</strong>:<br>In this process, the ISA pointer of the observed object is directed from the original class a, and is modified by the KVO mechanism to point to the <strong>newly created subclass </strong>Nskvonotifying_a Class of the system to <strong>enable the listener to change the current class property value</strong> . So when we look at the application level, Completely unaware of the emergence of new classes, This is the system "hide" the kvo of the bottom of the implementation process, let us mistakenly think or the original class.</li> <li><strong>analysis of the subclass setter Method:</strong> Kvo's key value observation notification relies on the two methods of Nsobject: willchangevalueforkey: and didchangevlueforkey:, 2 methods are called before and after the access value: before the observed attribute changes, Willchangevalueforkey: called to notify the system that the property value of the KeyPath is about to change, when the change occurs, didchangevalueforkey: is called, notifies the system that the value of the KeyPath property has changed; ObserveValueForKey:ofObject:change:context: It will also be called.</li> </ol></li> </ul> </ul> </ul><p><p>BAT Interview Preparation-ios</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service