Ios+oc face question
The difference between shallow copy and deep copy? Shallow copy and deep copy
Answer:
Shallow copy: Copies only pointers to objects, not the reference object itself. This object is accessed by a pointer to the object
Deep Copy (mutablecopy): Copy the Reference object itself
The meaning is that there is 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. When a is modified, a copy is unchanged.
To make a metaphor: 1, shallow copy is: You hang up, your mother shout you go home to eat when you can not find people, she is very sad. 2, deep copy is: You cloned a yourself: you hung up, your brother is still in, your mother called you home to eat when you can find people. So, children, on the safe side, deep copy it, remember memory management just.
category do? What is the difference between inheritance and category in implementation?
answer: category can add new methods in the case of not knowing, not changing the original code, can only add, cannot delete the modification. Category: Class, Kind
and if the category and methods in the original class produce name conflicts, the class overrides the original method because the category has a higher priority. The category and class priority
category has 3 functions:
(1) disperses the implementation of the class into multiple different files or multiple different frameworks. The
(2) Creates a forward reference to the private method.
(3) Adds an informal agreement to the object.
Inheritance can add, modify, or Delete methods, and you can add properties.
//Informal protocol: is implemented using category categories, which is a category of NSObject, so that objects of any class can be used as delegate objects, which can list all the methods that an object can execute to implement a delegate, We can use selectors to determine if this method is available in the informal protocol.
Formal agreement: is a named method list, different from the informal protocol, it requires the display of the adoption Protocol, the method of adopting the protocol is to list the name of the protocol in the @interface declaration of the class, at this time, the class implementing the protocol should abide by the Protocol, commitment to implement all the methods in the Protocol.
3 The difference between category and class extension.
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. What is the difference between a protocol in OC and an interface concept in Java?
Answer: The agent 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)".
5. What are 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. KVC used a isa-swizzling technique. Isa-swizzling is the type-mixed pointer mechanism. KVC mainly through the isa-swizzling, to achieve its internal search and positioning. The ISA pointer, which is the meaning of the is a kind of, points to the class that maintains the sub-published object. This sub-publication actually contains pointers to the methods in the implementation class, and other data.
KVO (Key-value observing): A key-value observation mechanism that provides a way to observe a change in a property, greatly simplifying the code.
One of the places used is the monitoring of the button click Change Status.
Like a button that I've customized. KVO provides automatic message notification when the property changes. Each time the property changes, a message notification is sent. This is because when the program has been clearly defined, to obtain framework-level support, can be easily adopted, the law-opener does not need to design their own observation of the model, can be used directly in the project. The Kov architecture can support multiple observers observing the same property, as well as related values.
[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 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.
The type can be modified and not modifiable in
7.oc.
answer: You can add changes dynamically and not add changes dynamically.
such as 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. 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. The problem with
is that it involves two concepts, runtime and polymorphism. 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. The
//is used in the same way that different objects respond to the same message in their own way.
Therefore, it can also be said that the runtime mechanism is the basis of polymorphism
9. What are the differences between notifications and agreements?
answer: the protocol has a control chain (has-a) relationship, the notification is not. Notification: It can be one-to-many, a message can be sent to multiple message recipients, but the message
Control chain: Single-owned and controllable correspondence is not processed.
10. About polymorphism
answer: polymorphic, the subclass pointer can be assigned to the parent class. An
object can exist not just by its own type, but also as its parent class type. Polymorphism is a technique that allows the parent object to be set to be equal to one or more of its child objects, and polymorphism enables the use of pointers of the same class (base class) type to refer to objects of different classes, and to perform the same operation differently depending on the referenced object.
11. Say the response chain
answer: event response chain. Includes click events, screen refresh events, and more. Propagates from top to bottom or from bottom to top of the view stack.
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)//frame: frame, struct
bounds refers to the position and size of the view in its own coordinate system. (The reference point is its own coordinate system)//bounds: Bounds
14. The nsoperation queue
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 data on the web point out that, although it is a queue, but not with the concept of queuing, put the operation is not in accordance with strict advanced show.
Here another doubt is that for the queue, the concept of FIFO is Afunc added to the queue, bfunc tightly followed also into the queue, Afunc first to perform this is inevitable,
but Bfunc is waiting for Afunc complete operation, b before starting and execution, So the concept of the queue agitation a bit against the concept of multithreading.
But on the other, I can refer to the bank's ticket collection and station-to-station system.
Therefore, for a-B queue to get tickets but B to take the lead in the operation, we can also feel that this is a queue.
But later saw a vote on the topic of the operation of the article, one of the sentences mentioned
"because two operations commit the time interval is very close, thread pool of threads, who first started is uncertain." "
instantly think this queue name is a bit of a flicker of people, not as good as pool~
, we know that he can be a big use to help the group multithreaded programming.
15. Do you want to embed two TableView controllers in one view controller?
answer: A view control only provides a view, theoretically a tableviewcontroller cannot be put,
can only be said to embed a tableview view. 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
16. Can a tableview be associated with two different data sources? What would you do with it?
Answer: First, from the code point of view, how the data source Association, in fact, is implemented in the proxy method associated with the data source.
-(UITableViewCell *) Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
if (indexpath.section = = 0)
{
}
if (indexpath.section = = 1)
{
}
}
17. What is the ID type
A variable of type ID can hold an object of any data type. In internal processing, this type is defined as a pointer to an object, which is actually a pointer to an instance variable of such an object.
Example: ID number
Declare number as a variable of type ID. The declared method has the return value of the ID type, as follows:
-(ID) newObject; (int) type;
This program declares an instance method named NewObject with a single integer parameter named type and a return value of type ID. It should be noted that for return values and parameter type declarations, the ID is the default type.
The ID type is the very Chinese medicine shop data type in Objetive-c, which is the basis for polymorphism and dynamic binding.
Ios+oc face question