[Interview] interview questions for iOS development (2)

Source: Internet
Author: User

[Interview] interview questions for iOS development (2)
1. What do we mean when oc is a dynamic runtime language?
Answer: polymorphism. It mainly delays the determination of data types from compilation to runtime.
This problem actually involves two concepts: runtime and polymorphism.
Simply put, the runtime determines the class of an object and calls the specified method of the Class Object until it is run.
Polymorphism: the ability of different objects to respond to the same message in their own way is called polymorphism. This means that we assume that biological classes (life) use the same method-eat;
Humans belong to creatures, and pigs also belong to creatures. After they all inherit life, they implement their own eat. However, we only need to call their own eat methods.
That is, different objects respond to the same message in their own way (response to the eat selector ).
Therefore, we can also say that the runtime mechanism is the basis of polymorphism ?~~~


2. What are the differences between notifications and protocols?
Answer: The Protocol has a control link (has-a). No notification is sent.
To put it simply, a notification can be one-to-multiple, and one message can be sent to multiple message recipients.
According to our understanding, agents do not directly say that they cannot be one-to-many. For example, if we know a celebrity economic representative, a single economic person is often responsible for the affairs of Several stars.
It is only for different stars that the agent objects are different and correspond to each other. It is impossible to say that A star needs to handle A press conference tomorrow. After the agent sends A message to handle the press conference, B's
The press conference was launched. But the notification is different. He only cares about sending the notification, but does not care about how many notifications he is interested in.
Therefore, the control chain (has-a) roughly shows the correspondence between a single ownership and a controllable English word.


3. Polymorphism
Answer: polymorphism. Subclass pointers can be assigned to the parent class.
This question can actually come out of all object-oriented languages,
Therefore, we recommend that you have a self-conscious understanding of polymorphism, inheritance, and encapsulation, and do not necessarily include the information written in the book.
The most important thing is to turn into self-understanding.


4. What is the difference between frame and bounds?
Answer: frame refers to the position and size of the view in the parent view coordinate system. (The reference point is the father's coordinate system)
Bounds indicates the position and size of the view in its own coordinate system. (The reference point is its own coordinate system)



5. NSOperation queue?
Answer: The collection class that stores NSOperation.
The operation and operation queue can basically be seen as the concept of threads and thread pools in java. It is used to handle ios multi-thread development issues.
Some materials on the Internet mentioned that although it is a queue, it is not a concept with a queue. The put operations are not strictly advanced.
There is another question here: for a queue, the concept of first-in-first-out is that Afunc is added to the queue, and Bfunc is followed into the queue. Afunc is required to execute it first,
However, Bfunc is started and executed only after Afunc is fully operated. Therefore, the concept of queue is a little different from that of multi-thread processing.
However, you can refer to the Bank's ticketing and calling system.
Therefore, for A to get votes in the queue before B, but B is the first to complete the operation, we can also perceive this as A queue.
However, I saw an article about this queue topic, one of which mentioned
"Because the time interval between two operations is very close, it is not certain who starts the thread in the thread pool ."
In an instant, I think this queue name is a little dumb. It's not as good as pool ~
To sum it up, we know that he can be of great use in helping with multi-thread programming.


6. What is delayed loading?
Answer: The Lazy mode is initialized only when used.
It can also be understood as delayed loading.
I think the simplest column is the loading and display of images in tableView.
One delayed load prevents excessive memory and asynchronous loading to avoid thread congestion.


7. are two tableview controllers embedded in one view controller?
Answer: A View control only provides one View. Theoretically, a tableViewController cannot be used,
Only one tableview can be embedded. Of course, the question itself is also ambiguous. If it is not the UIViewController we think in qualitative thinking,
It is a macro view controller, so we can regard it as a view controller, which can control multiple view controllers, such as TabbarController.
That way.


8. Can a tableView be associated with two different data sources? What do you do?
Answer: First of all, we can see from the code that how the data source is associated is actually implemented in the proxy method of the data source Association.
Therefore, we do not care about how to associate the data source. The method is to let me set the relevant data source according to my own needs.
Therefore, I think you can set up multiple data sources, but the question is, what do you want to do? How do I display the list and partition blocks of different data sources?


9. When will NSMutableArray and NSArray be used?
Answer: When the array is running, it needs to change constantly. When NSMutableArray is used, the array will not be changed after initialization. NSArray is used. It should be pointed out that NSArray only indicates that the array does not change during runtime, that is, it cannot add or delete elements to the array of nsarry, but it does not indicate that the content of the elements in the array cannot be changed. NSArray is thread-safe, and NSMutableArray is NOT thread-safe. Pay attention to the use of NSMutableArray in multiple threads.


10. Give an instance of the delegate method and state the Data Source method of UITableVIew.
Answer: a large number of delegates are used in the CocoaTouch framework. UITableViewDelegate is a typical application of the delegation mechanism. It is a typical use of delegation to implement the adapter mode. The UITableViewDelegate protocol is the target and tableview is the adapter, implement the UITableViewDelegate protocol and set itself as the delegate object of talbeview. It is an adapter. Generally, this object is UITableViewController.
The Data Source methods of UITableVIew include-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section;
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath;


11. What is a simple constructor?
Answer: The simple construction method is generally provided by the CocoaTouch framework, such as NSNumber + numberWithBool: + numberWithChar: + numberWithDouble: + numberWithFloat: + numberWithInt:
Most classes under Foundation have simple constructor methods. We can use simple constructor methods to obtain the objects created by the system for us without manual release.


12. What are predicates?
Answer: The predicate uses NSPredicate to filter data based on given logical conditions.
Predicate = [NSPredicate predicateWithFormat: @ "customerID = % d", n];
A = [customers filteredArrayUsingPredicate: predicate];


13. What about Block? And write an animation that uses Block to execute UIVew?
Answer: Block is an anonymous function that can obtain local variables of other functions. It is not only convenient for development, but also greatly improves the application execution efficiency (multiple core CPUs can directly process Block commands)
[UIView transitionWithView: self. view
Duration: 0.2
Options: UIViewAnimationOptionTransitionFlipFromLeft
Animations: ^ {[[blueViewController view] removeFromSuperview]; [[self view] insertSubview: yellowViewController. view atIndex: 0];}
Completion: NULL];


14. What is multithreading?
Multithreading is a complex concept. It literally means that multiple tasks are synchronized, which improves resource usage efficiency. From the perspective of hardware, operating system, and application software, multithreading is endowed with different connotations. For hardware, most of the CPUs on the market are now multi-core, and multi-core CPU operations are superior to multithreading. From the operating system perspective, multi-task, currently, the mainstream operating systems are multi-tasking, allowing you to listen to songs and write blogs. For applications, multithreading allows applications to respond more quickly. During Online downloads, responds to user touch operations at the same time. In iOS apps, the initial understanding of Multithreading is concurrency, which means that the original work of first cooking, then cooking, and then cooking will become a process of boiling water while taking dishes, finally, go to cooking.


15. multithreading in iOS
Multithreading in iOS is a multithreading in the Cocoa framework. Through Cocoa encapsulation, we can use threads more conveniently, those who have worked on C ++ may have a better understanding of the thread, such as the creation of the thread, the awareness of semaphores and shared variables, and the convenience of the Cocoa framework, it encapsulates threads and encapsulates some of them so that the objects we create can have the thread itself, that is, the object abstraction of the thread, thus reducing our project, the robustness of the provider.
GCD is short for Grand Central Dispatch. It provides an easy-to-use multi-threaded class library at the system level. It features runtime and fully utilizes multiple core hardware. The gcd api interface is a C-language function, and most of the function parameters have blocks. For details about the use of the Block, refer to here to provide us with a powerful "interface". For the use of GCD, see this article.
NSOperation and Queue
NSOperation is an abstract class that encapsulates detailed implementation of threads. We can subclass this object and add NSQueue to manage multi-threaded programs in the same way as Object-oriented thinking. For details, see here: a NSOperation-based multi-threaded network access project.
NSThread
NSThread is an object that controls thread execution. It is not as abstract as NSOperation. Through it, we can easily get a thread and control it. However, the concurrency control between NSThread threads needs to be controlled by ourselves and can be implemented through NSCondition.
See NSThread for iOS multi-thread programming
Other Multithreading
Under the Cocoa framework, multiple threads are used for notifications, Timer, and asynchronous functions (to be supplemented ).


16. When will GCD and NSOperation be selected for the project?
The advantage of using NSOperation in projects is that NSOperation is a highly abstract thread. using it in projects will make the program structure of the project better and subclass NSOperation design ideas, it has the advantages of object-oriented (reuse and encapsulation), so that the implementation is supported by multiple threads, while the interface is simple, it is recommended to be used in complex projects.
The advantage of using GCD in projects is that GCD itself is very simple and easy to use. For non-complex multi-threaded operations, it will save the amount of code, while the use of Block parameters will make the code easier to read, we recommend that you use it in a simple project.


17. What is block?

There are many definitions of closures (blocks). Closure is a function that can read internal variables of other functions. This definition is close to the essence and is easy to understand. If you are new to Block, you will find it a bit difficult, because we are used to writing such a program main () {funA ();} funA () {funB ();} funB () {.....}; That is, function main calls function A, function A calls function B... Functions are executed sequentially, but in reality they are not all like this. For example, project manager M has three programmers A, B, and C, when he arranged for programmer A to implement function F1, he did not wait for A to complete and then arranged B to implement F2. Instead, he arranged for function A F1, function B F2, and Function C F3, then he may write technical documents. When A encounters A problem, he will look for M, the project manager, and M will be notified when B completes. This is an example of asynchronous execution. In this case, Block can show its skills, because when the project manager M arranges work for A, it will also tell A if it encounters difficulties, how can I locate the problem reported by him (for example, calling his mobile phone number)? This is A callback interface provided by project manager M to A. the operation to be returned, for example, after receiving A call or Baidu query, return the webpage content to A. This is A Block, which has been defined during M's work and obtained the F1 Task Number (local variable ), it is called and executed only when A encounters A problem. The cross-function queries Baidu in project manager M and calls back the block after the result is obtained.

 

18. What is the garbage collection mechanism of OC?
Answer: OC2.0 has a Garbage collection, but it is not provided on the iOS platform.
In general, objective-c is manual for memory management, but there are also automatic release pools.
However, if most of the information is missing, it seems that we should not mix it with the arc mechanism.

 

19. block implementation principle
Objective-C is an extension of C language, and block implementation is based on pointers and function pointers.
From the development of computing language, the earliest goto, the pointer to advanced language, to the block of object-oriented language, from machine thinking to human thinking step by step, to facilitate developers to describe the real logic (requirements) more efficiently and directly ).
The following are two blog posts about block implementation.
Exploration of block implementation in iOS
Objective-C Block implementation
3 block usage
Use instance
Call the Block of the animation effect in the cocoaTouch framework
Use typed to declare a block
Typedef void (^ didFinishBlock) (NSObject * ob );
This declares a didFinishBlock block,
Then available
@ Property (nonatomic, copy) didFinishBlock finishBlock;
Declare a blokc object. Note that the object attribute is set to copy. When the block parameter is received, a copy is automatically copied.
_ Block is a special type,
The local variables declared using this keyword can be changed by the block, and their values in the original function will be changed.
4. Common series of interview questions
During the interview, the interviewer will first ask whether to understand block and whether block has been used. These questions are equivalent to opening remarks. They are often the beginning of the following series of questions. Therefore, you must answer them according to your own situation.
1. What are the advantages of using block and delegate to complete the delegation mode?
First, you need to understand what is the delegate mode. The delegate mode is widely used in iOS. In the design mode, it is the Object Adapter In the adapter mode. In Objective-C, the id type is used to direct to all objects, simplify the delegation mode. Understand the details of the delegation mode:
IOS design mode-delegation Mode
Using block to implement the delegate mode, the advantage is that the block code block of the callback is defined inside the delegate object function, making the code more compact;
The adaptation object no longer needs to implement a specific protocol, and the code is more concise.
2. multithreading and block
GCD and Block
Use the dispatch_async series methods to execute the block in the specified Method
GCD programming example
Full definition of dispatch_async
Void dispatch_async (
Dispatch_queue_t queue,
Dispatch_block_t block );
Function: Submit an asynchronous block in the specified queue without blocking the current thread.
Use queue to control the thread of block execution. The main thread executes the finishBlock object defined previously.
Dispatch_async (dispatch_get_main_queue (), ^ (void) {finishBlock ();});
 

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.