iOS development Face question (ii)

Source: Internet
Author: User
Tags ticket

1.Difference between shallow copy and deep copy?
The difference between shallow copy and deep copy?
Answer: Shallow copy: Copies only pointers to objects, not the reference object itself.
Deep copy: Copies the reference object itself.
That means I have an A object, after copying a copy to get A_copy object, for shallow copy, A and a_copy point to the same memory resource, copy is just a pointer, the object itself resources
There is only one copy, so if we do a modification to a_copy, then we find that the object referenced by A is also modified, which violates the idea of copying copies. Deep replication is a good idea, and there's an in-memory
Two copies of the independent object itself.
Using a friend on the Internet, the popular words will be:
Shallow copy is like you and your shadow, you are finished, your shadow is finished
Deep replication is like you and your clones, you're screwed, your clones are alive.

2.What is advantage of categories? What is difference between implementing a category and inheritance?
The role of the category? What is the difference between inheritance and category in implementation?
Answer: Category can be in the case of not knowing, without changing the original code to add a new method, can only add, can not delete the changes.
And if the category and methods in the original class produce name collisions, the category overrides the original method because the category has a higher priority.
There are 3 main functions of the category:
(1) The implementation of the class is dispersed across several different files or multiple frameworks.
(2) Create a forward reference to the private method.
(3) Add an informal agreement to the object.
Inheritance can add, modify, or Delete methods, and can add properties.

3.Difference between categories and extensions?
The difference between categories and class extensions.
Answer: The difference between category and extensions is that the latter can add attributes. In addition, the method that the latter adds must be implemented.
Extensions can be thought of as a private category.

4.Difference between protocol in Objective C and interfaces in Java?
What is the difference between a protocol in OC and an interface concept in Java?
Answer: The agreement in OC has 2 meanings, officially defined as formal and informal protocol. The former is the same as the Java interface.
The methods in informal protocol belong to the design pattern and are not required to be implemented, but if implemented, the properties of the class are changed.
In fact, regarding formal agreements, categories and informal agreements I have read about it very early in my studies, and I wrote it in my tutorial.
"The concept of informal agreement is actually another way of expressing a category" Here are some ways you might want to implement, and you can use them to do a better job. "
This means that these are optional. For example, we want a better way, we will declare a category to achieve. Then you can use these better methods directly later on.
In this way, I always feel that the category of this thing is a bit like an optional protocol. "
Now, in fact, Protocal has begun to unify and standardize the operation of both, because the data said "informal agreement using interface decoration",
Now we see two modifiers in the protocol: "must Implement (@requied)" and "optional implementation (@optional)".

The protocol in OC (formal protocol) is basically consistent with the interface concept in Java, and the informal Protocol (informal protocol) in OC is the category. In Java If you inherit the interface, but do not implement its methods, you will get an error (cannot compile), in the OC formal agreement, if not implemented, you will get a warning (can be compiled to execute), if you want to remove Waring, you can also add keywords (@optional), Let it be the optional implementation method.

5.What is KVO and KVC?
Answer: KVC: Key-value encoding is a mechanism that indirectly accesses an object's properties by using a string to identify the property, rather than by invoking an access method, either directly or through an instance variable.
In many cases, you can simplify your program code. The Apple documentation actually gives a good example.
Kvo: A key-value observation mechanism that provides a way to observe a change in a property, greatly simplifying the code.
specifically used to see that one of the places that hum used is the monitoring of the button click Change state.
such as a button I have customized
[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]; 
   } 

For the system is based on the keypath to the corresponding value changes, in theory, and KVC mechanism is the same reason.
For how the KVC mechanism looks for value through key:
"When invoking an object through KVC, such as: [Self valueforkey:@" Somekey "], the program automatically attempts to parse the call in several different ways. First find whether the object with Somekey this method, if not found, will continue to find whether the object with Somekey this instance variable (iVar), if not found, the program will continue to attempt to invoke-(ID) Valueforundefinedkey: This method. If this method is not implemented, the program throws a Nsundefinedkeyexception exception error.

(cocoachina.com Note: Key-value coding Find method, not only will find Somekey this method, but also find Getsomekey this method, preceded by a get, or _somekey and _ Getsomekey these several forms. At the same time, finding the instance variable will not only look for the variable somekey, but also find out if the _somekey variable exists. )

Design Valueforundefinedkey: The main purpose of the method is that when you use the-(ID) Valueforkey method to request a value from an object, the object can have a last chance to respond to the request before the error occurs. There are many benefits to this, and the following two examples illustrate the benefits of doing so. “
Come to cocoa, this statement should be quite reasonable.
Because we know that the button has a highlighted instance variable. So why do we just add a related keypath on top of that?
Can follow KVC find logical understanding, said the past.

6.What is purpose of delegates?
The role of the agent?
Answer: The purpose of the agent is to change or pass the control chain. Allows a class to be notified to other classes at certain times without having to obtain pointers to those classes. Can reduce the complexity of the frame.
On the other hand, a proxy can be understood as a similarity to the callback listener mechanism in Java.

7.What is mutable and immutable types in Objective C?
The type can be modified and not modifiable in OC.
Answer: You can modify the non-modifiable collection class. My personal simple understanding is that you can add changes dynamically and not add changes dynamically.
Like Nsarray and Nsmutablearray. The former in the initialization of the memory control is fixed immutable, the latter can be added, etc., you can dynamically request new memory space.

8.When We call Objective C are runtime language what does it mean?
What do we mean by the Dynamic runtime language of OC?
Answer: polymorphic. The main is to postpone the determination of the data type by compile time to the runtime.
This problem actually involves two concepts, runtime and polymorphism.
Simply put, the run-time mechanism allows us to determine the class of an object until run time, and to invoke the class object to specify the method.
Polymorphism: The ability of different objects to respond to the same message in their own way is called polymorphism. It means that a biological class (life) is-eat in the same way;
The human beings belong to the creatures, and the pigs belong to the creatures, and all inherit the life and realize their eat, but the call is the only way we call the Eat method.
That is, different objects respond to the same message in their own way (in response to the Eat selector).
So it can also be said that the runtime mechanism is the basis of polymorphism? ~~~

9.what is difference between nsnotification and protocol?
What are the differences between the notice and the agreement?
Answer: The protocol has a control chain (has-a) relationship, the notification is not.
First of all I didn't quite understand, what is called the chain of control (professional terminology ~). But simple analysis of the notification and agent behavior patterns, we can roughly have their own understanding
In short, it can be a one-to-many message, and a message can be sent to multiple recipient recipients.
Agent according to our understanding, to not directly say not a pair of more, such as we know the Star economic agent, many times an economic person responsible for several star affairs.
Just for different stars, agents of the objects are not the same, each corresponding, it is impossible to say tomorrow to deal with a star to a conference, the agent issued a message to deal with the conference, the nickname B
The press conference. But the notice is not the same, he only cares about giving notice, not caring how much receives interest to deal with.
So the control chain (has-a from English words can be seen roughly, a single ownership and controllable correspondence.

10.What is push notification?
What is a push message?
Answer: Too simple, do not answer ~~~~~~~~~~
This is the answer on the cocoa.
In fact, it is not too simple, just too general a concept of things. It's like saying, what is a man.
Push notifications are more of a technology.
A simple point is a means by which a client obtains resources.
In normal cases, the client is active pull.
Push is the server-side proactive push. The implementation of test push allows you to view the blog post.

11.Polymorphism?
About polymorphism
Answer: polymorphic, sub-class pointers can be assigned to the parent class.
This topic can actually be found in all object-oriented languages,
Therefore, on polymorphism, inheritance and encapsulation of the basic best have a sense of self-awareness, it is not necessary to write the information on the book can be memorized.
The most important thing is to translate into self-understanding.

12.Singleton?
For the understanding of the singleton
Answer: 11, 12 The topic actually has a somewhat general feeling, may say is the programming language needs or the essential foundation.
Basically you can write a single case in a familiar language, a scenario you can use, or a frame class that you've encountered in your programming.
Further points, consider the security of how to access a single instance in multithreaded.

13.What is responder chain?
Talk about the response chain
Answer: The incident response chain. Includes click events, screen refresh events, and more. Propagates from top to bottom or from bottom to top of the view stack.
It can be said that the distribution, delivery and processing of the incident. Specifically, you can look at the touch event this piece. Because the question is too abstract.
Serious doubts about the problem, the more the later the more general.

Can be from the chain of responsibility model, in terms of the incident response chain processing, its own extensibility

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 refers 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 is the difference between a method and a selector?
Answer: Selector is the name of a method, which is a combination that contains the name and 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 the iOS platform is not available.
Generally we know that objective-c is manual for memory management, but it also has an auto-release pool.
But most of the information, it seems not to be confused with the arc mechanism.
Ask for more ~ ~

17.NSOperation queue?
Answer: The collection class that holds the nsoperation.
Operations and operations queues, which can be seen as the concept of threads and thread pools in Java. A problem that is used to handle iOS multithreaded development.
Some of the information on the Internet mentioned that, although it is a queue, but not with the concept of queuing, put into the operation is not in accordance with the strict advanced show.
There is a doubt here, for the queue, the concept of FIFO is Afunc added into the queue, bfunc tightly followed also into the queue, Afunc first to do this is inevitable,
But Bfunc is waiting for Afunc complete operation, b just start and execute, so the concept of the queue in theory is a bit against the concept of multithreading.
But on the other, I would like to refer to the bank's ticket collection and system.
Therefore, for a than B queue to take the ticket but B first to perform the operation, we can also feel that this is a queue.
But then I saw a vote on the topic of the operation of the queue, one of the sentences mentioned
"Because two operations are committed in close proximity, threads in the thread pool, who start first are uncertain." ”
Instantly think this queue name is a bit of a flicker of people, it is better than pool~
To be more comprehensive, we know that he can be a big use to help with multithreaded programming.

Upstairs distinguishes between the order in which threads execute (afunc and Bfunc who start first) and the order in which threads execute (afunc and Bfunc who finish first), while the important concept of multithreading is concurrency (performing multiple tasks at the same time). Nsoperationqueue is an object that manages concurrent threads, where you can put the Nsopertation object (the object-based thread entity), control the number of concurrency by setting the size of the maxconcurrentoperationcount, as said upstairs. Afunc added into the queue, after the execution, Bfunc immediately into the queue, continue to execute ", that just set the Maxconcurrentoperationcount to 1, will be executed sequentially, this time is actually in a single thread sequentially. So the nsoperationqueue here is the object of abstraction to manage multi-threading, the benefit of the user by inheriting the Nsoperation object, you can easily use the object to manage the thread, and no longer with the care of thread synchronization, semaphore and other details, more attention to business logic.

18.What is lazy loading?
Answer: Lazy mode, only in the use of the time to initialize.
Can also be understood as delayed loading.
I think the best is also the simplest of a sample is the TableView in the picture loading shows.
A delay load, to avoid excessive memory, an asynchronous load, to avoid thread congestion.

19.Can we use the TableView controllers on one viewcontroller?
are two TableView controllers embedded in a single view controller?
Answer: A view control only provides a view, theoretically a tableviewcontroller can not put it,
Can only be said to embed a tableview view. Of course, the topic itself is ambiguous, if it is not our qualitative thinking of Uiviewcontroller,
Instead of a macro representation of the view controller, we can think of it as a view control that can control multiple view controllers, such as Tabbarcontroller
That kind of feeling.

20.Can we use one tableview with different datasources? How are you would achieve this?
Can a tableview be associated with two different data sources? What would you do with it?
Answer: First of all, from the code point of view, how the data source Association, in fact, is implemented in the proxy method associated with the data source.
So we don't care how to relate to him, how he relates, and the method just lets me go back and set the data sources as they are relevant to my needs.
So, I think I can set up multiple data sources, but there's a question: What do you want to do? How do you want the list to appear, with different data source partition blocks displayed?

iOS development Face question (ii)

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.