iOS development Face Question (intermediate)

Source: Internet
Author: User


Want to interview the children's shoes to see how much they will, the veteran can ignore direct bypass ...
1. Can the class of object-c inherit multiple? Can I implement more than one interface? What category is it? How do you rewrite a class in a way that inherits or classifies well? What is the main difference between extension and extension?
A: The class of object-c is not multiple inheritance; multiple interfaces can be implemented, and multiple inheritance of C + + can be accomplished by implementing several interfaces; Category is the classification (category, category), the general situation with good classification, the category to rewrite the method of the class, only valid for this category, will not affect the other classes and the original class relationship. Generally the category can only add methods, and extension can add methods and properties (both are private), but the category can be runtime.h objc_getassociatedobject/objc_ Setassociatedobject to access and build the associated object. This method is used to simulate the build properties. (You need to override the property's set and Get methods)

2. What is the difference between #import and # include, @class, #import <> and #import "" What's the difference?
A: #import是Objective-C import header file keyword, #include是C/c++ import header file keyword, using #import header file will automatically import only once, will not be repeated import (conditional compilation if define); Class tells the compiler that the declaration of some classes, when executed, to see the implementation of the class file, you can resolve the header file to avoid the mutual inclusion of the circular reference; #import <> header file used to contain the system, #import "" to contain the user header file.

3. What are the functions of readwrite,readonly,assign,retain,copy,nonatomic, in that case?
1. ReadWrite is a readable and writable feature; When getter methods and setter methods need to be generated;
2. ReadOnly is a read-only feature that only generates getter methods, does not generate setter methods, and does not want attributes to change outside of the class;
3. Assign is an assignment attribute, the setter method assigns the passed parameter to the instance variable; only when the variable is set;
4. Retain represents holding characteristics, setter method will pass in the parameters of the first reservation, and then assign value, the Retaincount of the incoming parameters will be +1;
5. Copy represents an assignment attribute, and the setter method copies the incoming object; When a new variable is required;
6. Nonatomic Non-atomic operation, determines whether the compiler-generated setter getter is an atomic operation, atomic for multithreading security, general use Nonatomic;atomic: When setting the @property property of a member variable, the default is atomic, Provides multithreading security. In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results. Adding the Atomic,setter function will change to the following:
{Lock}
if (Property! = newvalue) {
[Property release];
property = [NewValue retain];
}
{Unlock}
Nonatomic: Prohibit multi-threading, variable protection, improve performance.

4. For statement nsstring*obj = [[NSData alloc] init]; What type of object is obj at compile time and run time?
Compile-time is the type of nsstring; runtime is an object of type NSData

5. What is the difference between the data types of common object-c and the basic data types of C? such as: Nsinteger and int
OBJECT-C data types have nsstring,nsnumber,nsarray,nsmutablearray,nsdata and so on, these are class, after creation is the object, and C language basic data type int, just a certain byte of memory space, for storing values; Nsinteger is a basic data type, not a subclass of NSNumber, and certainly not a subclass of NSObject. Nsinteger is the alias of the base data type int or long (Nsinteger's definition typedef long Nsinteger), the difference is that Nsinteger determines whether it is an int or a long based on whether the system is 32-bit or 64-bit.

What is the nature of the object declared by 6.id?
An ID-declared object has a runtime attribute, which can point to an object of any type of objcetive-c;

7.objective-c How to do memory management, say your opinion and solution? Does OC have garbage collection wit? is iOS garbage collected?
OBJECTIVE-C memory management has three main ways of Arc (automatic memory count), manual memory count, memory pool.
1. (Garbage Collection) (garbage collection) automatic memory count: This is similar to Java in the course of your program's execution. Always have an expert in the back to help you clean up the rubbish, you do not have to consider when it began to work, how to work. You just need to understand, I applied for a memory space, when I no longer use so this memory becomes garbage, I completely forget it, anyway, the high man will help me to clean up the rubbish. Unfortunately, the man needs to consume a certain amount of resources, in the carrying device, the resources are tight goods so the iphone does not support this feature.
Resolution: Created by Alloc–initial, after the reference count of +1, after each retain reference count +1, then in the program to do the corresponding number of release is good.
2. (Reference counted) manual memory count: That is, after a period of memory is applied, there is a variable to save the memory is used, we temporarily call it a counter, when the counter becomes 0, then the time to release the memory. For example, when a piece of memory in program A is successfully applied, then the counter is changed from 0 to 1 (we call this process alloc), then program B also needs to use this memory, then the counter is changed from 1 to 2 (we call this process retain). Then program a no longer needs this memory, then program a will reduce this counter by 1 (we call this process release), program B also no longer need this memory, then also the counter minus 1 (this process or release). When the system (that is, the foundation) finds this counter to be 0, the memory recycle program is called to reclaim the memory (we call this process the Dealloc). By the way, if there is no foundation, then maintenance counters, free memory and so on, you need to do the work manually.
Workaround: Typically created by static methods of the class, the function name does not appear in the Alloc or Init typeface, such as [NSString string] and [Nsarray Arraywithobject:], after the creation of the reference count +0, after the function is released after the stack, is equivalent to a local variable on a stack. Of course, you can also extend the lifetime of an object by retain.
3. (autorealeasepool) Memory pool: You can control the timing of memory requests and recoveries by creating and freeing memory pools.
Workaround: The autorelease is joined to the system memory pool, the memory pool is nested, and each memory pool needs to have a create release pair, just like the one written in the main function. The use is also very simple, for example [[[[NSString alloc]initialwithformat:@] Hey you! "] Autorelease], a NSString object is added to the most internal system memory pool, and when we release the memory pool, the objects are freed.

8. What is the method for creating threads in Object C? What is the method if you execute code in the main thread? What is the method if you want to defer execution of code?
There are three ways to create a thread: Use Nsthread to create, use GCD dispatch, use a subclass nsoperation, and then add it to Nsoperationqueue; Execute code on the main thread. The method is Performselectoronmainthread, if you want to delay the execution of code can be used PerformSelector:onThread:withObject:waitUntilDone:

9. Describe how to implement the MVC development model in the iOS SDK
MVC is a model, a view, a controller development pattern, for the iOS SDK, all views are view layers, which should be independent of the model layer and controlled by the view control layer. All user data is the model layer and should be independent of the view. All Viewcontroller are control layers that are responsible for controlling views, accessing model data, and implementing communication between the model and the view.

10. What is the difference between a shallow copy and a deep copy?
Answer: Shallow copy: Copies only pointers to objects, not the reference object itself.
Deep copy: Copies the reference object itself. Meaning that 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 is a resource or only one copy, if we do the A_copy modified operation, Then we find that the object referenced by A is also modified, which in fact violates the idea of copying copies. Deep replication is a good understanding that there are two independent objects in memory.

11. 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.
KVO: A key-value observation mechanism that provides a way to observe a change in a property, greatly simplifying the code.
Like a button I've customized.
[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, 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 (crash).
(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 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 this 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.

12. What do we mean by OC, which is the runtime language of the dynamic runtime?
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 the biological class (life) has the same method-eat, the human belongs to the organism, the pig also belongs to the biology, all inherits the life, realizes the respective eat, but the invocation is we only need to call the respective Eat method. That is, different objects respond to the same message in their own way (in response to the Eat selector). Therefore, it can also be said that the runtime mechanism is the basis of polymorphism.

13 What is a push message?
Answer: First step: Send the phone's Bouldid (unique logo of the app) and Udid (unique identifier of the phone) to APNs
The second step: APNs received, send a token to the user's phone top
Step three: The user sends tokens to the server that they want to be pushed
Fourth step: The server sends tokens and messages to be pushed to APNs
Fifth step: APNs According to token to find the user, the message to wake up the way to push over

14. Write an implementation section of a singleton creation method
Answer: 1. Add lock
+ (Singleton *) shareinstance
{
@synchronized (self) {//Add a sync lock to this method, limit the same time two threads cannot access simultaneously
if (s = = nil) {
s = [[Singleton alloc] init];
}
}
return s;
2.GCD
Create a single case
+ (Instancetype) sharetotaldownloader{
static Totaldownloader *total = nil;
Static dispatch_once_t Oncetoken;
Dispatch_once (&oncetoken, ^{
Total = [[Totaldownloader alloc] init];
});
return total;
}
}

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)



 
What animations have you used for iOS development?
Answers: Commonly used are: UIView animation, Calayer animation, block animation, frame animation (GIF), etc.
17. How do I save data in the iphone app?
Answer: There are several preservation mechanisms:
1. Save on the server via remote service
2. Save the object in a local file via Nsuserdefault
3. Save in the local file database via SQLite or CoreData.

18. Talk about the understanding of block? and write a uivew animation using block?
Answer: Block is an anonymous function that can get local variables of other functions, which is not only convenient for development, but also can greatly improve the execution efficiency of the application (multi-core CPU can directly handle the block instruction)
[UIView TransitionWithView:self.view
duration:0.2
Options:uiviewanimationoptiontransitionflipfromleft
animations:^{[[Blueviewcontroller view] removefromsuperview]; [Self view] insertSubview:yellowViewController.view atindex:0]; }
Completion:null];

19. When does the project choose to use GCD and when to choose Nsoperation?
The advantage of using nsoperation in a project is that Nsoperation is a high abstraction of the thread, using it in the project, will make the program structure of the project better, the sub-class nsoperation design idea, is has the object-oriented advantage (multiplexing, encapsulation), so that the implementation is multi-threaded support, The interface is simple and recommended for use in complex projects.
The advantage of using GCD in a project is that the GCD itself is very simple and easy to use, saving code for uncomplicated multithreaded operations, and the use of block parameters is more readable and recommended for simple projects.

Block
1 What are the advantages of using block and using delegate to complete the delegation mode?
The first thing to understand is the delegate mode, which is used extensively in iOS, which is an object adapter in the adapter pattern in design mode, and OBJECTIVE-C uses the ID type to point to everything, making the delegate mode more concise. Learn the details of the delegate model:
2. Briefly describe the difference between block and agent
Proxy: Requires write protocol, proxy method and set proxy object block need to define block, implement block, call block
Delegate
1, "One to one", to the same protocol, an object can only set a proxy delegate, so the singleton object can not be used proxy;
2, agents pay more attention to the transmission of process information: for example, to initiate a network request, you may want to know whether the request has started, whether the data received, whether the data has been accepted to complete, the data received failed
Block
1: More concise writing, no need to write protocol, functions, etc.
2,block results-oriented transmission: for example, for an event, just want to know the success or failure, do not need to know how much or additional information
3,block need to be aware of preventing circular references:
(In Arc, if the __strong modifier's automatic variable is referenced in the block, it is equivalent to a block reference count of the variable +1, under Arc, because the __block grab variable will be retain by the block, you must use a weak reference to solve the circular reference problem , IOS 5 can be used directly after the __weak, before you can only use __unsafe_unretained, __unsafe_unretained disadvantage is that the pointer released itself will not be empty)
ARC:
__weak typeof (self) weakself = self;
[Yourblock:^ (Nsarray *repeatedarray, Nsarray *incompletearray) {
[Weakself dosomething];
}];
Non-arc:
__block typeof (self) weakself = self;
[Yourblock:^ (Nsarray *repeatedarray, Nsarray *incompletearray) {
[Weakself dosomething];
}];

iOS development Face Question (intermediate)

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.