Inventory 2016 iOS development questions and answer finishing

Source: Internet
Author: User

Today, as mobile internet technology continues to evolve and innovate, interviews are now a time-consuming project for both companies and developers and designers, and they are filtered and aggregated in the face of problems that iOS developers and designers may encounter during an interview. Let's have a look here.

1, briefly describes the memory management mechanism in OC. The method used for pairing with retain is dealloc or release, why? The method that needs to be paired with Alloc is Dealloc or release, why? readwrite,readonly,assign,retain,copy , the role of Nonatomic, Atomic, strong, weak attributes?

Management mechanism: a mechanism called reference counting is used to manage objects in memory. Each object in OC corresponds to their own reference count, which can be interpreted as an integer counter, and the holding count is automatically set to 1 when the object is created using the Alloc method. When you send a retain message to an object, the hold count value increases by 1. Conversely, when you send a release message like an object, the hold count value is reduced by 1. When the holding count of an object becomes 0, the object frees up the memory it occupies.

Retain (reference count plus 1)->release (reference count minus 1)

Alloc (Request memory space)->dealloc (free memory space)

ReadWrite: Indicates both getter and setter (default)

ReadOnly: Indicates only getter, no setter

Nonatomic: Do not consider thread safety

Atomic: Thread operation Security (default)

Setter and getter in thread-safe situations:

-(nsstring*) value {

@synchronized (self) {

return [[_value retain] autorelease];

}}

(void) SetValue: (nsstring*) Avalue {

@synchronized (self) {

[Avalue retain];

[_value release];

_value = Avalue;

} }

Retain:release the old object, assigns the value of the old object to the input object, and then increases the index count of the input object to 1

Assign: Simple assignment, does not change index count (default)

Copy: Actually create an identical object with different address (retain: pointer copy copy: content copy)

Strong: (Under Arc) and (MRC) retain (default)

Weak: (under Arc) and (MRC) assign, weak automatically nil when the pointing memory is released, preventing the wild pointer

Unsafe_unretained declares a weak application, but does not automatically nil, that is, if the area of memory pointed to is released, the pointer is a wild pointer.? autoreleasing is used to modify the parameters of a function, This parameter is automatically freed when the function returns.

2. @protected of class variables, @private, @public, @package, what are the meanings of the declarations?

@private: The scope of action can only be in its own class

@protected: scope in itself class and inherit its own subclass (default)

@public: The scope is the largest and can be accessed from anywhere.

@package: This type is most commonly used as an instance variable of a framework class, which can be used within the same package and cannot be accessed across packets

3. What is a thread? What is a process? What are the differences and connections?

A program has at least one process, and a process has at least one thread:

Process: One run of a program, with independent memory units during execution, and multiple threads sharing a piece of memory

Thread: A thread refers to an execution unit within a process.

Contact: A thread is the basic constituent unit of a process

Difference: (1) Dispatch: Thread as the basic unit of dispatch and allocation, process as the basic unit with resources? (2) Concurrency: Not only can concurrent execution between processes, but also concurrent execution between multiple threads of the same process? (3) Owning a resource: a process is an independent unit that owns resources, and threads do not own system resources, but they can access resources that belong to the process. (4) Overhead: When you create or revoke a process, the overhead of the system is significantly greater than the cost of creating or revoking a thread, because the system allocates and reclaims resources for it.

Example: The operating system has multiple software running (QQ, office, music, etc.), these are a process, and each process has a lot of threads (such as QQ, you can chat at the same time, send files, etc.)

4. What is your understanding of multithreaded development? How many ways to implement multithreading in iOS?

Benefits:

1. Using threads can put tasks in a long-time program in the background to handle

2. The user interface can be more attractive, such as the user clicked a button to trigger the processing of certain events, you can pop up a progress bar to show the progress of processing

3. The program may run faster

4 · Threads are useful for tasks such as user input, file read and write, and network send and receive data.

Disadvantages:

1. If you have a large number of threads, it can affect performance because the operating system needs to switch between them.

2. More threads require more memory space.

3. The termination of a thread requires consideration of its impact on the program's operation.

4. Usually block model data is shared across multiple threads, and it is necessary to prevent thread deadlock situations from occurring.

Ways to implement Multithreading:

NSObject class method

Nsthread

Nsoperation

GCD

5. What are the differences between thread synchronization and async? How does multi-threaded synchronization work in iOS?

Async: A simple example is a game in which the game will have images and background music

Synchronization: Refers to a thread that waits for the last thread to execute before it starts executing the current thread, toilet

Nsoperationqueue:maxcurrentcount

Nsconditionlock

6, if there is a string Aabcad, write a program, remove the string is not adjacent to the repeating string, that the above string processing after the output is: AABCD

nsmutablestring * str = [[nsmutablestring alloc]initwithformat;@ "Aabcad"];

for (int i = 0, i < str.length-1; i++) {

unsigned char a = [str characteratindex:i];

for (int j = i + 1, J < Str.length, J + +) {

unsigned char b = [Str characteratindex:j];

if (a = = b) {

if (j = = i + 1) {

}else{

[Str Deletecharactersinrange:nsmakerange (J, 1)];

}

}

}

}

NSLog (@ "%@", str);

7. What are the methods for obtaining a unique identification of a device?

(1) UDID

(2) Uuid

(3) MAC Address

(4) OPEN UDID

(5) Advertising identifiers

(6) Vindor identifiers

8. Can iOS classes inherit more? If not, can it be implemented in any other way? A brief introduction to the implementation process.

Can not be more inherited with protocol implementation

9. What is the difference between heap and stack?

Heap requires the user to manually free the memory, while the stack is the compiler automatically frees the memory

Problem extension: Know how nsstring memory is stored in OC

10. What are the different ways of iOS local data storage?

Nskeyedarchiver

Nsuserdefaults

Write Writing method

SQLite3

(Problem extension: What kind of data storage is used)

1.NSKeyedArchiver: In the form of archiving to save data, data objects need to adhere to the Nscoding protocol, the object corresponding to the class must provide Encodewithcoder: and Initwithcoder: Method. Cons: Only one-time archive save and one-time decompression. So only for a small amount of data, the operation of the data is clumsy, if you want to change a small part of the data, you need to extract or archive the entire data.

2.NSUserDefaults: Used to save application settings and properties, user-saved data. The data still exists after the user opens the program again or after powering it on. The types of data that Nsuserdefaults can store include: NSData, NSString, NSNumber, NSDate, Nsarray, Nsdictionary. Disadvantage: If you want to store other types, you need to convert to the previous type in order to use nsuserdefaults storage.

3.Write write mode: Permanently saved on disk. The first step: Get the path of the file to be saved: Step two: Generate files under this path: Step three: Write data to the file: finally: Read the data from the file:

4. SQLite: Use SQLite database to store data. SQLite as a small and medium-sized database, the application of iOS, in front of three ways to save compared to a relatively more complex.

11. Write a method to get iOS memory usage.

Gets the current device's available memory and the header file of the occupied memory

#import

#import

Get current device available memory (in MB)

-(double) availablememory

{

vm_statistics_data_t Vmstats;

mach_msg_type_number_t infocount = Host_vm_info_count;

kern_return_t Kernreturn = Host_statistics (Mach_host_self (),

Host_vm_info,

(host_info_t) &vmstats,

&infocount);

if (Kernreturn! = kern_success) {

return nsnotfound;

}

Return ((Vm_page_size *vmstats.free_count)/1024.0)/1024.0;

}

Gets the memory occupied by the current task in megabytes (MB)

-(double) usedmemory

{

task_basic_info_data_t TaskInfo;

mach_msg_type_number_t infocount = Task_basic_info_count;

kern_return_t Kernreturn = Task_info (Mach_task_self (),

Task_basic_info,

(task_info_t) &taskinfo,

&infocount);

if (Kernreturn! = kern_success

) {

return nsnotfound;

}

return taskinfo.resident_size/1024.0/1024.0;

}

12. What is safe release?

Reset Nil and release

13, write a standard macro min, this macro input two parameters and return the smaller one?

#define MIN (x, y) (() > (Y)? ( Y):(X))

Extension: What issues do you need to be aware of when defining macros?

Macro all uppercase write in #import @interface end no semicolon

14. Does the iphone OS have a garbage collection mechanism? Briefly describe OC memory management.

iphone OS no garbage collection mechanism OC memory management is who created who released the program encountered retain that object reference count +1 met release the object reference count-1 retaincount for 0 o'clock memory release

15. Briefly describe the life cycle when the application presses the home key into the background, and the life cycle from the background back to the foreground?

You can write a demo to test it.

When entering the background

-(void) Applicationwillresignactive: (uiapplication *) application;

-(void) Applicationdidenterbackground: (uiapplication *) application;

When entering the front desk

-(void) Applicationdidenterforeground: (uiapplication *) application;

-(void) Applicationwillresignactive: (uiapplication *) application;

16, Viewcontroller Alloc,loadview, Viewdidload,viewwillappear,viewdidunload,dealloc, Init, respectively, when was the call? What should be done in these functions when customizing Viewcontroller?

Write your own code test to deepen your understanding

Alloc called when requesting memory

Loadview called when loading a view

Viewdidload view has been loaded after the call

Called when the Viewwillappear view will appear

The Viewdidunload view has been loaded but not loaded out of the call

Dealloc called when the view is destroyed

Called when Init view is initialized

17. Describe the startup order of the application.

1. The program entry main function creates the UIApplication instance and the UIApplication proxy instance.

2. Override the Startup method in the UIApplication proxy instance and set the first Viewcontroller.

3. Add the controls in the first Viewcontroller to implement the application interface.

18, why many built-in classes such as Uitableviewcontrol's Delegate property are assign instead of retain? Please give an example.

Prevent circular references

19, the use of UITableView time must be implemented in several ways?

-(Nsinteger) TableView: (uitableview*) Tableviewnumberofrowsinsection: (nsinteger) section;? This method returns the number of rows per segment, and different segments return different rows, which can be done with a switch, and if a single list returns a single function that you want.-(uitableviewcell*) TableView: (uitableview*) Tableviewcellforrowatindexpath: (Nsindexpath) Indexpath;? This method returns each cell that we call. Determined by the section and row of the path we indexed

20, write a convenient constructor.

The ID represents any type of pointer, which represents student *, class method

+ (ID) studentwithname: (NSString *) newName andage: (int) newage? {? Student *stu=[[student alloc]initname:newname andage:newage];? return [Stu autorelease];//auto release?}

21, UIImage initialization of a picture there are several ways to describe the advantages and disadvantages of each.

3 kinds

Imagenamed: The system will first check if there is an image of that name in the system cache, and if so, return it directly, and if not, load the image to the cache before returning.

Initwithcontentsoffile: The system does not check the system cache and is loaded and returned directly from the file system.

ImageWithCGImage:scale:orientation when scale=1

Inventory 2016 iOS development questions and answer finishing

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.