Summary of OC interview questions for iOS development

Source: Internet
Author: User

Summary of OC interview questions for iOS development

1. Briefly describe the memory management mechanism in OC

The memory management mechanism of OC is automatic reference technology. The principle of memory management is who opens up who releases the memory, which is divided into ARC and MRC. MRC requires our programmers to manually manage the memory, we do not need to manually manage the memory of the ARC, and the system will manage it on its own.

2. What are the functions of readwrite, readonly, assign, retain, copy, nonatomic, atomic, strong, and weak attributes?

ReadWrite read/write feature, readable and writable.

Readonly read-only, only getter, no setter.

Assign is generally used for basic data types and ID types.

Copy, which is generally used for NSString. It can be divided into deep copy and shortest copy. The deep copy Copies objects, and the shortest copy objects are pointers.

Nonatomic is non-atomic and does not take thread security into account. It has the advantage of high efficiency.

Atomic atomicity, with the advantage of thread security, and its disadvantage is low efficiency.

Strong reference, the same as the retain in MRC. weak reference, similar to assign in MRC. however, it should be noted that both strong and weak modify the attributes of the object type and cannot modify the basic data type. the basic data type is still modified using assign under ARC.

3. Questions about iOS Multithreading

Read: http://www.cocoachina.com/ios/20150731/12819.html

4. Suggestions for improving UITableView Performance

1. cell height calculation (you can use an array to return the height of a cell based on the Content height array)

2. Reuse of cells

3. When the cell slides fast, the image is not loaded. When the slides are stopped, the image is loaded.

4. Avoid blocking the main thread

5. cache downloaded Images

6. Do not use Xib too much (use storyboard if possible)

7. Use CoreGraphics

8. Transparency

Can also be carefully read: http://www.cocoachina.com/ios/20150729/12795.html

6. What is the difference between thread synchronization and Asynchronization?

Synchronization: A thread can be executed only after the execution of the previous thread is completed. Examples in life (toilet ).

Asynchronous: perform two or more threads at the same time. For example, you can listen to songs and read reports.

7. What is the difference between stack and stack?

Stack: the stack is automatically assigned and released by the compiler to store the parameter values and local variable values of the function. Advanced and later

Heap-usually assigned and released by programmers. First-in-first-out

Global (static) -- global variables and static variables. The program is released by the system.

Text Constant Area -- constant strings are stored here. The program is released by the system.

Code area-stores the binary file of the function body.

8. Can I inherit more iOS classes?

No. You can use delegate, protocol, and category to implement similar multi-inheritance.

9. Which of the following methods are available for iOS local data storage? How does iOS store complex objects?

1. Write mode: permanently stored in the disk. Only NSString, NSData, NSArray, and NSDictionary are supported.

2. NSKeyedArchiver (archive) stores data in an archive format. The data object must comply with the NSCoding protocol.

3. SQLite (FMDB) Note that FMDB is not a database, but an SQLITE management framework.

4. Remember that CoreData is not a database, and its core storage philosophy is hosting objects. But we often use SQLite as the storage file. XML, binary, and other methods can also be used.

10. Dynamic iOS

1. Dynamic type. For example, id type. In fact, static types are more widely used because of their fixation and predictability. The static type is strongly typed, while the dynamic type is weak. The runtime determines the receiver.

2. dynamic binding. Let the Code determine the method to be called at runtime, rather than during compilation.

3. dynamic loading. Allow the program to add code modules and other resources at runtime.

11. What is the meaning of deep copy and light copy?

The content is copied in deep copy, and the pointer is copied in light copy. If the address of the subclass object is changed, the object is copied in depth and vice versa.

12. What is secure release?

Set the pointer to nil after release in the object dealloc.

13. How to implement a singleton.

+ (ZMYSingleton *) sharedInstance {

StaticLOSingleton * sharedInstance = nil;

Staticdispatch_once_tonceToken; // thread lock

Dispatch_once (& onceToken, ^ {

// Call at most once

SharedInstance = [[ZMYSingletonalloc] init];

});

ReturnsharedInstance;

}

13. What is RunLoop?

A RunLoop is a loop of event processing. It is used to schedule tasks and process input time continuously. The purpose of using runloop is to make your thread busy at work, and sleep when it is not at work. The main objective is to reduce unnecessary idling of the cpu. Each thread has a Runloop, Which is enabled by default during the main thread's Runloop. The manually opened sub-thread Runloop is disabled by default. If it needs to be enabled, you need to call API [[nsunloopcurrentrunloop] run] to enable this function.

The most common method to enable Runloop is to call the timer (NSTimer) in the Child thread. If the runloop method is not enabled, it cannot be executed normally.

14. Write a standard macro MIN. This macro inputs two parameters and returns a smaller one?

# DefinekMIN (X, Y) (X)> (Y ))? (Y) :( X)

15. Briefly describe the lifecycle of an application when it enters the background by pressing the Home key, and when it returns to the foreground from the background?

Enter the background lifecycle:

-(Void) applicationWillResignActive :( UIApplication *) application;

-(Void) applicationDidEnterBackground :( UIApplication *) application;

Go back to the front-end for the lifecycle:

-(Void) applicationWillEnterForeground :( UIApplication *) application;

-(Void) applicationDidBecomActive :( UIApplication *) application;

16. When is the loadView, viewDidLoad, viewWillAppear, viewDidUnload, dealloc, and init of ViewController called? What should I do in the Custom ViewController functions?

LoadView: The nib view page is not in use. The subclass creates its own custom view layer.

ViewDidLoad: called after being loaded

ViewWillAppear: called when an attempt is made to appear

ViewDidUnload: Call when the system memory is tight, release the attempt not shown in the window and the corresponding Controller

17. describes the startup sequence of the application.

1. Create a UIApplication instance and a UIApplication proxy instance using the main function.

2. Rewrite the startup method in the UIApplication proxy instance and set the first ViewController

3. Add controls to the first ViewController to implement the corresponding program interface.

18. Why do the attributes of the write proxy all belong to assign rather than retain? For example.

Prevent loop reference,

Teacher * teacher = [[Teacheralloc] init];

Student * student = [[Studentalloc] init]; t

Eacher. delegate = student;

Student. delegate = teacher;

In teacher, dealloc will release the current Delegate, trigger the student object release, and then cause student to execute dealloc. In student, it will also release its own delegate and generate a loop.

19. How can I Initialize an image through UIImage? Briefly describe their respective advantages and disadvantages.

Two types:

1. Read from the resource. Check whether the image exists in the cache first. If not, add the image to the cache before using it. if yes, use the cache directly. this method is used when images are used more often. the disadvantage is inefficiency. UIImage * image = [UIImageimageNamed: @”1.png "];

2. read from the mobile phone and directly add images. this parameter is used when the image usage is low. // read the local image without resourceNSString * aPath3 = [NSStringstringWithFormat: @ "% @/Documents @.jpg", NSHomeDirectory (), @ "test"]; [UIImageimageWithContentsOfFile: aPath3]

20. Is there any problem with this Code:

@ ImplementationPerson

-(Void) setAge :( int) newAge {

Self. age = newAge;

}

@ End

Endless loop

21. Write a bubble sort with OC

NSMutableArray * array = [NSMutableArrayarrayWithArray: @ [@ "3", @ "1", @ "10", @ "5", @ "2", @ "7 ", @ "12", @ "4", @ "8"];

For (inti = 0; I <array. count; I ++ ){

For (intj = 0; j <array. count-1-I; j ++ ){

If ([[arrayobjectAtIndex: j] integerValue]> [[arrayobjectAtIndex: j + 1] integerValue]) {

[ArrayexchangeObjectAtIndex: jwithObjectAtIndex: j + 1];

}

}

}

NSLog (@ "% @", array );

22. Your understanding of UIView, UIWindow, and CALayer

UIView inherits from UIResponder, while UIResponder inherits from NSObject to respond to user events. The UIView build interface is used to display content, focusing on content management.

CALayer inherits from NSObject and cannot respond to events. Focuses on Content Rendering and animation processing, and relies on UIView for display.

UIWindow is a special UIView. Generally, an app only has one UIWindow. We can create a View Controller and add it to UIWindow, in this case, the view controller is the First Responder of the app ).

23. Differences between frame and bounds:

Frame: Position of the view in the parent view Coordinate

Bounds: Position of the view in the local coordinate

Center: The position of the center of the view in the parent view

Can also be carefully read: http://blog.csdn.net/mad1989/article/details/8711697

24. Write a complete proxy

25. What is the difference between json and xml analysis? What is the underlying Parsing Method of json and xml?

XML is a general extension Markup Language (SGML) that is suitable for Web transmission. Provides a unified way to describe and exchange data.

JSON (JavaScriptObjectNotation) is a lightweight data exchange format with good readability and ease of writing. Data exchange can be performed between different platforms.

26. When was didReceiveMemoryWarning of ViewController called? What is the default operation?

Call this function when a memory warning occurs. Release unused reusable objects. This method cannot be called manually !!!

27. Three features of object-oriented architecture, and a brief introduction

Encapsulation, inheritance, and polymorphism.

Encapsulation: encapsulates objective objects into abstract classes, hides internal implementations, and provides external interfaces.

Inheritance: all functions of an existing class can be used, and these functions can be extended without re-writing the original class.

Polymorphism: different objects respond to the same message in their own way.

28. put it simply, lazy loading

Initialization when used. If not used, Initialization is just a pointer and does not occupy memory space.

29. What are categories and extensions respectively? And the difference between the two? What is the difference between inheritance and category implementation? Why does Category only support adding methods to objects, but not member variables?

Category: A class extension method without knowing the source code,

Extension: Declares private methods and variables for a class.

Inheritance creates a new class.

30. # What is the difference between import, # include, and @ class?

# Introduce the header file in includeC, and cross-compilation may occur.

# Import introduce the self-created header file in OC

# Import "is the header file that introduces the self-created class.

# Import <> is the header file that introduces the system class.

# No cross-compilation occurs in import.

@ Class declares a class and tells the compiler that this class exists, but the class definition is unknown.

31. How do you understand MVC? Why use MVC? How is MVC implemented in Cocoa? Are you familiar with other OC design patterns or other design patterns?

MVC is the Model-VIew-Controller. Model data model, view is the display of this data, viewcontroller is to take the model to the view display, play the role of a bridge between model and view. MVC can achieve the highest degree of reusability of the program. Separate MVC elements can also facilitate code update and maintenance and improve code reusability.

Singleton mode, delegate design mode, and target-action Design Mode

32. String replacement method:

[StringstringByReplacingOccurrencesOfString: @ "png" withString: @ ""]

33. For the statement NSString * testObject = [[NSDataalloc] init]; what types of objects are testObject during compilation and runtime?

The NSString type is used for compilation, and the NSData type is used for running.

34. What is sandbox )? Which files are contained in the sandbox and the application scenarios of each file are described. How do I obtain the paths of these files? How do I obtain the file path in the application package?

IOS applications can only read files in the file system created for the program. They cannot be accessed elsewhere. This area is a sandbox that stores all non-code files. (For example, icon, sound, image, attribute list, text file, etc .)

By default, each sandbox has three folders: Documents, Library, and tmp.

Documents: stores the file data created or browsed in the program.

This directory will be included during iTunes backup and recovery

Library/Caches: stores cached files. iTunes does not back up this directory, and files in the directory are not deleted when the application exits.

Tmp: provides a place to create temporary files in real time.

During synchronization with the iPhone, iTunes backs up all Documents and Library files.

When the iPhone restarts, It discards all tmp files.

35. What are the roles of isKindOfClass and isMemberOfClass?

-(BOOL) isKindOfClass: classObj determines whether it is an instance of this class or this class subclass.

-(BOOL) isMemberOfClass: classObj determines whether it is an instance of this class.

36. The life cycle and iOS program execution sequence of UIViewController in iOS:

View control object Lifecycle

Init-initialization program

ViewDidLoad-load View

Called when the view of the viewWillAppear-UIViewController object is about to be added to the window;

Called when viewDidApper-UIViewController object view has been added to the window;

Call viewWillDisappear-when the view of the UIViewController object is about to disappear, be overwritten, or be hidden;

Called when the viewDidDisappear-UIViewController object's view disappears, is overwritten, or hidden;

Viewemediunload-this function is called when the memory is too low and you need to release unnecessary views;

ViewDidUnload-called when the memory is too low and some unnecessary views are released.

Specific reference: http://blog.csdn.net/huifeidexin_1/article/details/7566226

37. multithreading.

A: Grand Central Dispatch (GCD) is a solution for multi-core parallel computing. There are two main Queues: parallel and serial.

NSOperationQueue implements multithreading in the form of a queue and is encapsulated based on GCD.

NSThread is lightweight and multithreading. It is not commonly used. Disadvantages: You need to manage the thread lifecycle and synchronize the thread. Thread Synchronization locks data with a certain amount of system overhead

39. This issue involves the "memory alignment" issue of the compiler:

For example:

For struct, the largest byte in the member is float, which occupies 4 bytes and has 3 members. Therefore, the total byte occupied is 4*3 = 12. you can use the compiler command to set: # progmapack (2)

40. TCP/IP connection creation process:

In TCP/IP, TCP provides reliable connection services and uses three-way handshakes to establish connections;

First handshake: when a connection is established, the client sends a connection request to the server and enters the SYN_SEND status, waiting for confirmation from the server;

The second handshake: when the server receives a connection request from the client and sends a request to the client to allow connection responses, the server enters the SYN_RECV status;

The third handshake: the client receives the server's allowed connection response and sends a confirmation message to the server. The client and the server enter the communication status and complete the three handshakes.

(A three-way handshake is the process of sending and receiving three-way connection information. The establishment of a TCP connection requires sending and receiving three connection information .)

41. What is the difference between UDP and TCP?

The full name of TCP is the transmission control protocol, which can provide connection-oriented, reliable, and point-to-point communication.

The full name of UDP is the user data packet protocol. It can provide non-connection and unreliable point-to-point communication. It is a connectionless transport layer protocol in the osi reference model and provides simple and unreliable transaction-oriented information transmission, _ IETFRFC 768 is the formal specification of UDP;

The Protocol to choose depends on which aspect the program focuses on, which is reliable or fast.

42. Role of the static keyword

Static global variables

Advantages:

1. Memory saving. Static variables are only stored in one place, but are used by all objects.

2. Its value can be updated.

3. Time efficiency can be improved. Once an object is updated to a static variable, all objects can access the updated value.

43. What are the layers of the iOS system framework?

1. Core OS is the Core operating system layer, including memory management, file system, power management, and some other operating system tasks.

2. Core Services is the Core service layer used to access some iOS Services.

3. Media is the Media layer. Through this layer, we can use various Media files in an application to record audio and video, draw images, and create basic animation effects.

4. Cocoa Touch is a touchable layer. Essentially, Cocoa Touch is responsible for user Touch interaction on iOS devices.

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.