IOS interview question collection 1 (with basic answers)

Source: Internet
Author: User

This interview question contains 40 questions. It is a hot one that can be found online, but the answer is not very detailed and complete. The basic answer is cocoachina, and some of your own supplements.

1. Difference between shallow copy and deep copy?

What is the difference between shallow replication and deep replication?

Answer: copy the pointer to the object instead of the referenced object.
Deep replication: Copies the referenced object itself.

That is to say, I have an object A. After copying a copy and getting the_copy object, for the shortest copy, A and a_copy point to the same memory resource, and the copy is just a pointer, object Resource

There is only one copy. If we perform the modification operation on a_copy, we will find that the object referenced by A is also modified, which violates the idea of copying. Deep replication is easy to understand, and memory exists

Two independent objects.

The popular words on the Internet will be:

Copying is like a shadow between you and you. You are finished, and your shadow is finished.
Deep replication is like cloning you and your clone. You are finished and your clone is still alive.

2. What is advantage of categories? What is difference between implementing a category and inheritance?

What is the role of a category? What are the differences between inheritance and category implementation?

Answer: you can add a new method to the category without learning or changing the original code. You can only add the method, but cannot delete the modification.

In addition, if the category conflicts with the method in the original class, the category overwrites the original method because the category has a higher priority.

Category has three main functions:
(1) Distribute the implementation of classes to multiple different files or different frameworks.
(2) create a forward reference to a private method.
(3) add informal protocols to objects.

Inheritance can be added, modified, or deleted, and attributes can be added.

3. Difference between categories and extensions?

The differences between category and class extension.

Answer: The difference between category and extensions is that the latter can add attributes. In addition, the method added by the latter must be implemented.

Extensions can be considered as a private category.

4. Difference between protocol in Objective C and interfaces in Java?

What is the difference between the Protocol in OC and the interface concept in Java?

Answer: The agent in OC has two meanings: formal and informal protocol. The former is the same as the Java interface.

The methods in informal protocol belong to the scope of design pattern Consideration and are not required. However, if there is an implementation, the attributes of the class will be changed.

In fact, I have read about formal protocols, types, and informal protocols a long time ago and have written them in the course of study.

"The concept of informal protocols is actually another expression of categories." Here are some methods you may want to implement. You can use them to better complete the work ".
This means that these are optional. For example, if we want a better method, we will declare such a category to implement it. Then you can directly use these better methods later.
In this case, we always think the category is a bit like an optional protocol. "

Now we can see that protocal has begun to unify and standardize the two, because the document says "informal protocols use interface modifier",

Now we can see two modifiers in the Protocol: "must be implemented (@ requied)" and "Optional implementation (@ optional )".

5. What are KVO and KVC?

Answer: KVC: Key-value encoding is an indirect access object attribute that uses a string to identify the attribute, instead of calling an access method, or directly accessing the attribute through instance variables.

In many cases, program code can be simplified. The apple documentation provides a good example.

KVO: the key-value observation mechanism. It provides a method to observe the changes of a certain attribute, greatly simplifying the code.

You can see that one of the places you have used is monitoring the status of button click changes.

For example, a Custom button

[self addObserver:self forKeyPath:@"highlighted" options:0 context:nil];#pragma mark KVO- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{    if ([keyPath isEqualToString:@"highlighted"] ) {        [self setNeedsDisplay];    }}

In theory, the system changes the value obtained based on keypath, which is the same as the KVC mechanism.

How to find the value through the key of the KVC mechanism:

"When calling an object through KVC, for example, [self valueforkey: @" somekey "], the program will automatically try to parse the call in several different ways. First, check whether the object has the somekey method. If it is not found, it will continue to find whether the object has the somekey instance variable (Ivar). If it has not been found, the program will continue to try to call-(ID) valueforundefinedkey: This method. If this method is still not implemented, the program will throw an nsundefinedkeyexception error.
 
(Cocoachina.com Note: When the key-value coding search method is used, it not only searches for the somekey method, but also the getsomekey method. A get is added to the front, or _ somekey and _ getsomekey. In addition, when searching for instance variables, we will not only look for the somekey variable, but also find whether the _ somekey variable exists .)
 
Design valueforundefinedkey: when you use the-(ID) valueforkey method to request a value from an object, the object can have a final chance to respond to the request before an error occurs. There are many benefits to doing so. The following two examples illustrate the benefits of doing so. "

Come to cocoa, this statement should be quite reasonable.

Because we know that there is a highlighted instance variable in the button, we just need to add a related keypath,

You can follow the KVC search logic to understand the logic.

6. What is purpose of delegates?

What is the role of proxy?

Answer: The proxy aims to change or transmit the control chain. Allows a class to notify other classes at certain times without obtaining pointers to those classes. This reduces the complexity of the framework.

In addition, the proxy can be understood as a similar callback listening mechanism in Java.

7. What are mutable and immutable types in Objective C?

Types that can be modified or not modified in OC.

Answer: you can modify unchangeable collection classes. In my personal understanding, dynamic addition and modification are the same as dynamic addition and modification.

For example, nsarray and nsmutablearray. The former memory control after Initialization is fixed and immutable, and the latter can be added, and new memory space can be dynamically applied.

8. When we call Objective C is runtime language what does it mean?

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 ?~~~

9. What is difference between nsnotification and protocol?

What are the differences between notifications and protocols?

Answer: The Protocol has a control link (has-a). No notification is sent.

First of all, I didn't quite understand what a control chain is ~). However, we can understand the behavior patterns of notifications and proxies in a simple analysis.

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.

10. What is push notification?

What is push message?

Answer: This is too simple to answer ~~~~~~~~~~

This is the answer on cocoa.

In fact, it is not too simple, but a concept that is too general. It is like saying, what is a person.

Pushing notifications is a technology.

Simply put, the client Obtains resources.

Generally, pull is the active pull of the client.

Push is actively pushed by the server.

11. polymorphism?

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.

12. Singleton?

Understanding of Singleton

Answer: I think the question is actually a bit generic. It may be a programming language need or a necessary foundation.

You can write a single example in a familiar language, a scenario that can be used, or a framework class that you have encountered in programming.

Further, consider how to ensure security when multiple threads access a single instance.

13. What is responder chain?

Talk about the response chain

Answer: Event Response chain. Including click events and screen refresh events. Spread from top to bottom in the view stack or from top to bottom.

It can be said that point events are distributed, transmitted, and handled. For details, see the touch event. Because the question is too abstract

Seriously suspect that the more general the question is, the more general it will be.

14. Difference between frame and bounds?

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)

15. Difference Between method and Selector?

How is the method different from the selector?

Answer: Selector is the name of a method. method is a combination of names and implementations.

For more information, see the apple documentation.

16. Is there any garbage collection mechanic in Objective C .?

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.

More ~~

17. 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.

18. What is lazy 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.

19. Can we use two tableview controllers on one viewcontroller?

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.

20. Can we use one tableview with two different datasources? How you will achieve this?

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?

In itself, there are 40 questions in this IOS interview question set, but there are no answers to the 20 questions below. The LZ directly says, "The following is too simple to be said ~~~ "

In addition, the answer can be generalized rather than directly defined.

Therefore, next week I will take the time to pick out the remaining 20 questions that seem a little interesting. Then I will look for other questions and prepare for 20 more questions.

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.