IOS: Knowledge Point Brief answer

Source: Internet
Author: User

1. What is the difference between heap and stack?

A: For the stack, is automatically managed by the compiler, without our manual control, for the heap, release work by the programmer control, easy to produce memory leak.

2. What is the difference between an array and a linked list?

A: arrays are storing elements in memory continuously, because each element occupies the same memory, you can quickly access any element in the array by subscript.

The list is reversed, and the elements in the list are not stored sequentially in memory, but are linked by pointers in the elements that exist.

3. What is the difference between delegate and notification, and what are the conditions used?

A: Delegate: The sender of the message informs the receiver that an event is about to occur, Delegate agrees and then the sender responds to the event, and the Delegate mechanism allows the receiver to change the sender's behavior. Usually the relationship between the sender and the receiver is a direct one -to-many relationship.

Notification: The sender of the message informs the receiver that the event has occurred or is about to be sent, and that the recipient does not in turn affect the sender's behavior. usually the relationship between the sender and the receiver is indirect, many-to-many relationships.


4, what is MVC, why use MVC, what are the benefits?

A: Model, view, and control controller, respectively.

The model data model is used to encapsulate data related to the business logic of the application and how to handle the data.

"Model" has the right to direct data access, such as access to the database.

The View view layer enables the data to be displayed with purpose.

Controller controllers play an organizational role across different levels to control the flow of applications.

Reduced dependence on the controller, low coupling.

5, from an array to find the duplicate elements printed out

For:

Nsarray *arr = [nsarrayarraywithobjects:@"1",@"2",@"1",@"7",@"4",@"5",@"2",@"6",@"5", nil]; Nsmutablearray*arrmu = [[Nsmutablearrayalloc]init];//FilterNsmutablearray *samearray = [[Nsmutablearrayalloc]init];//Find the same    for(inti =0; i < [Arrcount]; i++) {      IDstr =[arr objectatindex:i]; if([arrmu count] = =0) {[ARRMUADDOBJECT:STR]; }       Else{BOOL flag=NO;  for(intj =0; J < [Arrmucount]; J + + ) {               if([Strisequal:[arrmu objectatindex:j]]) {[SAMEARRAYADDOBJECT:STR]; Flag=YES;  Break; }               Else{flag=NO; }            }           if(Flag = =NO)            {[ARRMUADDOBJECT:STR]; }}} NSLog (@"Samearray:%@", Samearray);

There are two more ways to find out directly, on the code:

One:

    Nsarray *arr = [nsarrayarraywithobjects:@ "1",@ "2",@ "  1", nil];     *Set = [Nssetsetwitharray:arr];    NSLog (@ "%@", [setallobjects]);

Two:

    Nsarray *arr [email protected][@1, @2, @1];     *dict = [nsmutabledictionarydictionary];      for (NSNumber *
{ [dictsetObject:numberforKey:number]; } NSLog (@ "%@", [dictallvalues]);

6. Can uitableview bind multiple data sources?

Answer: theoretically achievable.

7. Can a uiviewcontroller manage multiple uitableview?

Answer: You can

8. What are the new features added to iOS4, 5, 6 versus previous versions?
This is a lot more, such as: Abandon Google Maps new push maps application, greatly strengthen China localization support, Siri Open Mandarin, through the icloud experience to share the fun, Passbook e-ticket management, anytime, anywhere FaceTime, phone enhancements, Safari supports full screen browsing, mail app new VIP, Universal assistance: more powerful and so on

9. What is the difference between a synchronous request and an asynchronous request?

A: Send a synchronization request, the program will stop user interaction, until the server returned data to complete, before the next operation;

Asynchronous requests do not block the main thread, but create a new thread to operate, and after the user makes an asynchronous request, the UI can still be manipulated and the program can continue to run.


10, multi-threaded operation in iOS, multi-threaded mode

A: iOS provides a convenient multi-threaded calling mechanism: Nsoperation and Nsoperationqueue. It is also very simple to use, usually the Nsoperation object is added to the Nsoperationqueue queue, after joining the queue to start processing, know that the task operation is complete.


11. Uiviewcontroller Life Cycle

Answer: When a view controller is created and displayed on the screen. Order of execution of code
1. The order in which the view is displayed on the screen

1Alloc//create objects and allocate space. 2 3Init (Initwithnibname)//initializes the object and initializes the data. 4 5Loadview//loading views from the nib, this step does not need to interfere. Unless the view is created using the Xib file. 6 7Viewdidload//after loading, you can customize the data and create other controls dynamically. 8 9Viewwillappear//The view will appear in front of the screen, and this view is about to appear on the screen right away. Ten  OneViewdidappear//The view has been rendered on the screen.  A  -     

2. The order in which the view will be removed from the screen

1 // The view will be executed before being removed from the screen.  23//  view has been removed from the screen.  45//  views are destroyed, and objects created in Init and viewdidload need to be freed.  67//  memory warning occurs when there is insufficient storage and is executed for all controllers that are not currently displayed. 

All child views of this view will be destroyed to free up memory, at which point developers need to manually free memory for objects created in Viewload, Viewdidload. Because when the view is displayed again on the screen, Viewload and viewdidload are called again to construct the view again.

12. When will the Autorerelease object be released?

A: Autorelease actually just delayed the call to release, and for each autorelease, the system simply placed the object in the current Autorelease pool, and when the pool was released, All object in the pool is called release.


13, iOS Data persistence mode

Answer: Four kinds: Attribute list, Object archive, SQLite3 and core Data

14, Object-c class can inherit multiple? Can I implement multiple interfaces? What is category? Is it better to rewrite a class in a way that inherits or classifies? Why?

A: Object-c class is not multiple inheritance, can implement multiple interfaces, through the implementation of multiple interfaces can accomplish multiple inheritance of C + +; category is a class, the general situation with a good classification, the category to rewrite the method of the class, only for this category valid, Does not affect the relationship of other classes to the original class.

What is the difference between the #import and # include, @class, #import<> and #import "" What 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, do not repeat the import, equivalent to # include and #pragma once @class tell the compiler of a class declaration, when executed, to see the implementation of the class file, you can resolve the header file of each other, #import <> used to include the system header file, #import "" to include the user header file.

16. What are the functions of readwrite,readonly,assign,retain,copy,nonatomic, in that case?

A: ReadWrite is a readable writable feature; When you need to generate getter and setter methods

ReadOnly is a read-only feature that only generates getter methods and does not generate setter methods; Do not want attributes to change outside of the class

Assign is an assignment attribute, the setter method assigns the passed-in parameter to the instance variable, and only when the variable is set;

Retain represents the holding characteristics, setter method will pass in the parameters of the first reservation, and then assign value, the Retaincount of the passed parameter will be +1;

Copy represents an assignment attribute, and the setter method copies a copy of the incoming object, when a completely new variable is required.

Nonatomic non-atomic operations, determines whether the compiler-generated setter getter is an atomic operation, atomic represents multithreading security, and is generally used nonatomic

17. What are the common object-c data types, and what is the difference between the basic data types of C? such as: Nsinteger and int

A: Object-c data type has nsstring,nsnumber,nsarray,nsmutablearray,nsdata and so on, these are class, created is the object, and C language basic data type int, only a certain byte of memory space For storing values, while Object-c's NSNumber contains methods for NSObject of the parent class and nsnumber its own method to accomplish complex operations.

18.objective-c How to manage the memory, say your opinion and solve the method? A: Objective-c's memory management mainly has three ways arc (automatic memory count), manual memory count, memory pool. Solution: Who holds, who releases. 19. How do I perform a performance test on my iOS device?

Answer:profile-> Instruments->time Profiler

What is the method for creating threads in 20.Object C? If you execute code in the main thread, what is the method? What if you want to delay the execution of code and methods?

A: 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 by Performselectoronmainthread, if you want to delay the execution of code can be used PerformSelector:onThread:withObject:waitUntilDone:

21. Describe how to implement the MVC development model in the iOS SDK

A: MVC is: Model-view-control development mode, for iOS SDK, all views are view layer, it should be independent of the model layer, 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, which are responsible for controlling the view and accessing the model data.

22. When defining attributes, what is the use of copy, assign, retain? A: Assign for simple data types, such as nsinteger,double,bool, in fact, there are blocks, etc. retain and copy used for objects, copy is used when a point to an object, B also want to point to the same object, if using assign,       A If you release, then call B will crash, if you use copy, A and b each have their own memory, you can solve the problem.       Retain will add one to the counter, can also solve the problem of assign. Additionally: Atomic and nonatomic are used to determine whether the getter and setter generated by the compiler are atomic operations.       In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results. Adding the Atomic,setter function will change to the following:
if (Property! = newvalue) {       [property release]       ; = [newvalue retain];       }

Does Object-c have a private method? What about private variables?

A: There are only two methods in the Objective-c– class, static methods and instance methods, all instance variables are private by default, and all instance methods are public by default.

24. What is the difference between a shallow copy and a deep copy

A: Shallow copy: Copies only pointers to objects, not the reference object itself.
Deep copy: Copies the reference object itself.

25. What is the automatic release pool and how does it work

A: When you send an autorelease message to an object, cocoa puts a reference to the object into the latest auto-free pool.

It is still a legitimate object, so other objects within the scope defined by the auto-release pool can send messages to it. When the program executes at the end of the scope,

The auto-free pool is freed and all objects in the pool are freed.

26. What is a single-piece instance?

A: Some classes in the Foundation and application Kit framework allow only single-piece (singleton) objects to be created, which is the only instance of these classes in the current process.

For example, the Nsfilemanager and Nsworkspace classes are instantiated on a process-by-case basis using a single object.

When you request instances from these classes, they pass you a reference to a single instance, and if the instance does not already exist, the instance is assigned and initialized first.

27. What is the role of the category? What is the difference between inheritance and category in implementation?
A: Category can not be learned, do not change the original code in the case of adding a new method, can only add, can not delete the changes.

And if the class and the 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 a category:

? (1) Spread the implementation of the class into multiple 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.

28. Differences between categories and class extensions.
A: The difference between category and extensions is that the latter can add attributes. The other method that the latter adds is the one that must be implemented. Extensions can be considered a private category.

29.KVO and KVC??
For:KVC: Key-value encodingis a property of an indirect access object that uses a string to identify a property, rather than a mechanism that accesses it directly or through an instance variable by invoking an Access method.? In many cases, you can simplify your program code. The Apple documentation actually gives a good example.KVO: Key-value observation mechanism, he provides a way to observe a change in a property, greatly simplifying the code. The specific use to see the use of a place is for the button click on the change status of monitoring. For example, one of my custom
UIButton *button =[[UIButton alloc] init];? [Button addobserver:self Forkeypath:@"highlighted"Options0Context:nil];???#pragmaMark-kvo??-(void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID)ObjectChange: (nsdictionary *) Change context: (void*) context?    {  ? if([KeyPath isequaltostring:@"highlighted"] ) { ? UIButton*button = (UIButton *)Object; NSLog (@"%d", button.highlighted); }  }
For the system is based on the keypath to the corresponding value changes, in theory, and the KVC mechanism is the same as the truth. How to find the value of the KVC mechanism 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. (Note: Key-value coding Find method, not only will find Somekey this method, but also look for Getsomekey this method, preceded by a get, or _somekey and _getsomekey in 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. "It should make sense to come to cocoa." Because we know that a button has a highlighted instance variable. So why do we just add a related keypath on the line,? You can follow the logical understanding of KVC lookup, and that's the past. 30. What is the role of the agent?
A: The purpose of the agent is to change or transfer the control chain. Allows a class to be notified to other classes at certain times without having to obtain pointers to those classes. You can reduce the complexity of the frame. The other point is that the agent can be understood as a similar kind of callback monitoring mechanism in Java. 31. 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. What's the difference between 32.frame and bounds??
A: 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 itself a coordinate system) 33. How are methods and selectors different??
Answer: Selector is the name of a method, which is a combination. Can the 34.object-c class inherit multiple? Can I implement multiple interfaces? Is it better to rewrite a class in a way that inherits or classifies? Why?
A: Objective-c only supports single inheritance, if you want to implement multiple inheritance, can be implemented by the way of categories and protocols, cocoa all classes are nsobject subclasses, multi-inheritance is implemented here with the protocol delegated agent. 35.ARC Automatic Reference counting A: 1.ARC is a compile attribute, not a runtime attribute, but the compiler automatically adds the release code when compiling
2. Cannot call release, retain, Autorelease, Retaincount
3.dealloc Note
1> cannot invoke [super Dealloc] in Dealloc
2> cannot release resources in Dealloc
[email protected]Parameter description
1> retain changed to strong
2> basic data type (int\float) or assign
3> Copy or copy
4> if 2 objects are referenced by a loop, one end is strong and one end is weak
5> Weak is used on the object, weak actually function with assign quite

IOS: Knowledge Point Brief answer

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.