This column will be updated continuously — please pay attention to iOS friends!
(The answer is not unique, only for reference, there are benefits in the back of the article oh ~)
IOS Interview Questions:
IOS Interview Collection + Answer (1)
IOS Interview Collection + Answer (2)
IOS Interview Collection + Answer (3)
IOS Interview Collection + Answer (4)
IOS Interview Collection + Answers (5)
IOS Advanced Interview questions —-Block (juejin.cn)
IOS Advanced Interview Questions —- Multi-threaded (juejin.cn)
1.Difference between shallow copy and deep copy?
What’s the difference between a shallow copy and a deep copy?
Answer: shallow replication: only the pointer to the object is copied, not the reference object itself.
Deep replication: copies the reference object itself.
What that means is that I have an object A, and I make A copy of it and I get an A_copy object, and for shallow replication, A and A_copy point to the same memory resource, and what I’m copying is just A pointer to the object itself
Or there is only one copy, so if we modify A_copy, then we find that the object referenced by A is also modified, which actually goes against the idea of copying. Deep copy makes sense. It exists in memory
Two separate objects themselves.
In the colloquial words of a friend on the Internet, it would be:
The shallow copy is like you and your shadow. You die, your shadow dies
Deep replication is like you and your clone, you’re screwed, your clone lives.
2.What is advantage of categories? What is difference between implementing a category and inheritance?
What do categories do? What is the difference between inheritance and classes in the implementation?
Answer: Category can add new methods to the code without learning, without changing the original code, can only add, not remove changes. And if a name conflict occurs between the category and a method in the original class, the category overrides the original method because the category has a higher priority. Categories have three main functions:
(1) Spread the implementation of the class across multiple different files or multiple different frameworks.
(2) Create a forward reference to a private method.
(3) Add an informal protocol to the object.
Inheritance can add, extend superclass methods, and can add attributes.
3.Difference between categories and extensions?
The difference between categories and class extensions.
The difference between category and Extensions is that attributes can be added to them. In addition, the latter method is added must be implemented. Extensions can be considered a private Category.
4.Difference between protocol in objective c and interfaces in java?
What are the differences between protocol in OC and interface concepts in Java?
A protocol in OC has two meanings, officially defined as formal protocol and informal protocol. The former is the same as the Java interface.
The methods in the Informal Protocol fall into the category of design pattern considerations and are not required to be implemented, but if implemented, will change the properties of the class.
I actually read about formal agreements, categories and informal agreements in my early studies, and in my tutorials
“The informal protocol concept is just another way of saying category,” Here are some ways you might want to implement them, and you can use them to get the job done better.”
What this means is that these are optional. For example, if we wanted a better method, we would declare a class to do it. Then you can use these better methods directly at a later stage.
In that sense, the category thing is kind of like an optional protocol for protocols.”
Now, Protocal has begun to unify and standardize both, because the source says that “informal protocols use interface decorators.”
Now we see two modifiers in the protocol: “Must implement (@requied)” and “Optional implement (@optional).”
The formal protocol in OC is basically the same as the interface concept in Java, and the informal protocol in OC is the category. In Java, if you inherit an interface but don’t implement its methods, you get an error (cannot compile). If you want to remove waring, you can add the keyword (@optional) to make it optional.
5.What are KVO and KVC?
Answer: KVC: Key-value encoding is a mechanism for indirectly accessing the properties of an object using strings to identify the properties, rather than by calling access methods, directly or through instance variables.
In many cases, you can simplify your program code. The Apple documentation actually gives a good example.
Kvo: Key-value observation mechanism, which provides a way to observe a property change, greatly simplifying the code.
One of the things that you see in ahem is the monitoring of the status of button clicks.
Let’s say I have a custom button
[cpp] [self addObserver:self forKeyPath:@”highlighted” options:0 context:nil];
[cpp] [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]; }}Copy the code
For the system is according to the keypath to take the corresponding value of the change, theoretically speaking is the same as the KVC mechanism.
How the KVC mechanism finds a value through a key:
“When an object is called through KVC, such as [self valueForKey:@” someKey “], the program automatically tries to parse the call in several different ways. If not, the program will continue to look for the instance variable (iVar). If not, the program will continue to try to call -(id) valueForUndefinedKey: this method. If the method is not implemented, an NSUndefinedKeyException will be thrown.
When looking for a key-value Coding method, not only will it look for someKey, but it will also look for getsomeKey with a get, or _someKey and _getsomeKey. Also, when looking for instance variables, we will not only look for someKey, but also _someKey.
ValueForUndefinedKey: The main purpose of designing the valueForKey: method is that when you use -(id)valueForKey to request a value from an object, the object has a last chance to respond to the request before an error occurs. There are many benefits to doing so, as illustrated by the following two examples. “Come to Cocoa, that might make sense.
Because we know that button does have a highlighted instance variable. Therefore, why we only add a relevant keypath above, which can be understood according to the logic of KVC search, makes sense.
6.What is purpose of delegates?
The role of agency?
Answer: The purpose of an agent is to change or pass on the chain of control. Allows a class to notify other classes at certain times without needing to get Pointers to those classes. You can reduce framework complexity.
On the other hand, the proxy can be thought of as an analogue to the callback listening mechanism in Java.
7.What are mutable and immutable types in Objective C?
The types can be modified and cannot be modified in oc.
Answer: modifiable but not modifiable collection classes. The simple understanding of this is that dynamically adding changes is the same as non-dynamically adding changes. Such as NSArray and NSMutableArray. The former after the initialization of the memory control is fixed and immutable, the latter can be added, can dynamically apply for new memory space.
8.When we call objective c is runtime language what does it mean?
What do we mean when we say oc is a dynamic runtime language?
Answer: polymorphism. The main thing is to defer data type determination from compile time to run time. The problem really involves two concepts, runtime and polymorphism. In simple terms, the runtime mechanism allows us to not determine the class of an object and call the methods specified for that class object until run time. Polymorphism: The ability of different objects to respond to the same message in their own way is called polymorphism. What that means is that suppose that the biological classes, “life,” all use the same method — eat; So humans are living creatures, and pigs are living creatures, and they inherit life, and they implement their own eat, but we just need to call each other’s eat method. That is, different objects respond to the same message in their own way (in response to the selector eat). So you can also say that the runtime mechanism is the basis of polymorphism, right? ~ ~ ~
9.what is difference between NSNotification and protocol?
What’s the difference between notice and agreement?
Answer: Protocols have a has-a relationship, notifications do not. First of all, I didn’t quite understand what the control chain was. But by looking at the behavior patterns of notifications and brokers, we can sort of get a sense of what that means. In short, notifications can be one-to-many, and one message can be sent to multiple message recipients. According to our understanding, the agent is not directly one to many. For example, we know the economic agent of stars. In many cases, one agent is responsible for the affairs of several stars. Just for different stars, the object of the agent is not the same, one by one, it is impossible to say that tomorrow to deal with A star to A press conference, agent issued after the news of the press conference, called B press conference. Notifications, on the other hand, are concerned only with sending them out, not with how much they receive and are interested in processing them. Thus the chain of control (has-a) is roughly the correspondence between single ownership and control.
10.What is push notification?
What is a push message?
Answer:. The notification push mechanism in iOS is also called message mechanism, which includes two types: one is local notification; The other category is push notifications, also called remote notifications. The two kinds of notifications have the same performance in iOS, which can be told to the user through the banner or pop-up reminder, and clicking on the notification can open the app, but the implementation principle is completely different: local notifications are triggered by the local app, which is a form of notification based on time behavior; Different from local notifications, Push notifications are initiated by application service providers and sent to application clients through Apple Push Notification Server (APNs), as shown in the following figure
11. Polymorphism?
About polymorphism
Answer: polymorphism, in which a parent pointer points to a subclass object. This topic can be applied to any object-oriented language, so it is best to have a self-aware understanding of polymorphism, inheritance, and encapsulation, and not necessarily to be able to recite what is written in books. The most important thing is to translate into self-understanding.
12.Singleton?
Understanding of singletons
Answer: 11,12 questions actually out of a bit of a general feeling, may be said to be a programming language needs or essential foundation. Basically write a singleton in a language you’re familiar with, as well as scenarios you can use or framework classes that you’ve encountered using this pattern in your programming. Further, consider how to secure singletons when multiple threads access them.
13.What is responder chain?
Talk about the response chain
Answer: Event response chain. Including click events, screen refresh events and so on. Propagates from top to bottom, or from bottom to top, within the view stack. You can say distribution, delivery and processing of point events. Look at the touch event. Because the question is too abstract serious doubt that the more the topic out of the more general.
14.Difference between frame and bounds?
What’s the difference between frame and bounds?
Answer: Frame refers to the position and size of the view in the parent view’s coordinate system. (The reference point is the father’s coordinate system.) Bounds refer to 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?
What’s the difference between methods and selectors?
A selector is the name of a method, and a method is a combination of a name and an implementation. See the Apple documentation for details.
16.Is there any garbage collection mechanism in Objective C.?
OC’s garbage collection mechanism?
Answer: OC2.0 has Garbage collection, but iOS does not. Most objective-C memory management as we know it is done manually, but there is also automatic pool release. But with most of the data missing, it’s probably best not to confuse it with the ARC mechanic. For more ~ ~
17.NSOperation queue?
Answer: the collection class that holds NSOperation. Operations and operation queues can basically be thought of as Java concepts of threads and thread pools. For dealing with ios multi-threaded development issues. One thing that some sources on the Internet mention is that although it is a queue, it does not have the concept of queue, and the operation of putting in is not strictly advanced. Here’s the problem. The first in, first out concept is that Afunc is added to the queue, and Bfunc is followed by Afunc. It’s inevitable that Afunc executes this first, but Bfunc doesn’t start and execute until Afunc has completed its operation. So the concept of queues is a bit of a theoretical violation of the concept of multithreading. On second thought, however, you can actually refer to the bank’s ticket collection and station-to-station system. So if A lines up before B to get the ticket but B finishes the operation first, we can also think of it as A queue. But then I saw a bunch of articles on the topic of operation queuing, and there was a sentence that said “Because of the close interval between the two operations, it is not clear who started first in the thread pool.” Queue: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool: pool
The NSOperationQueue is an object that manages concurrent threads. The NSOperationQueue is an object that manages concurrent threads. The NSOperationQueue is an object that manages concurrent threads. Threads can be put into the NSOpertation object (target entities), by setting the size of the maxConcurrentOperationCount, number of concurrent control, such as the upstairs said hope “Afunc added to the queue, after the execution, Bfunc followed into the queue, continue to implement”, That simply maxConcurrentOperationCount set to 1, the change will be executed in sequence, this time is actually executed in sequence in a single thread. Therefore, NSOperationQueue here is objectivated and abstract to manage multithreading. In this way, users can conveniently manage threads with objects by inherits NSOperation objects, and pay more attention to business logic instead of thread synchronization, semaphore and other details.
18.What is lazy loading?
Answer: Lazy mode, which is initialized only when it is needed. You can also think of it as delayed loading. I think one of the best and simplest examples is the loading and displaying of images in a tableView. One delayed load to avoid memory overload, and one asynchronous load to avoid thread congestion.
19.Can we use two tableview controllers on one viewcontroller?
Do you want to embed two TableView controllers in one view controller?
Answer: A View control provides only one View, and theoretically a tableViewController can’t put it in, except that it can embed a TableView. Of course, the title itself is ambiguous, if it’s not a UIViewController that we think of qualitatively, but a macro view controller, then we can think of it as a view controller, and it can control multiple view controllers, like a TabbarController.
20.Can we use one tableview with two different datasources? How you will achieve this?
Can a tableView associate two different data sources? How would you handle it?
Answer: First we look at the code, how the data source association, in fact, in the data source association proxy method implementation. So we don’t care how to correlate it, how to correlate it, the method just tells me to go back and set up the relevant data source according to my own needs. So, I think you can set up multiple data sources, but the question is, what are you doing here? How do you want the list to display, different data source partition blocks?
Bonus: A learning route reference for iOS developers