Basic Questions for iOS (1)

Source: Internet
Author: User

Kaikaijia sent a private message to me, saying that I want to add a group. I will create an iOS development group for technical exchanges and resources. Group Number:241048287If you are interested, you can add a group. The verification information is IOS + name.


IOS interview series:

IOS interview

Basic Questions for iOS (2)

Basic Questions for iOS (part 3)

Basic Questions for iOS (4)

As the number of positions developed on the iOS platform increases, there are more and more "routines" in the written examination and interview. Here I have summarized some interview questions, most of which are basic knowledge of objective-C and are suitable for interviewing new users, the answer is answered by myself, which is inaccurate.

1. Can object-C classes be inherited multiple times? Can multiple interfaces be implemented? What is category? Is the method of rewriting a class well inherited or well classified? Why?

The class of Object-C cannot be inherited in multiple ways; multiple interfaces can be implemented, and multiple inheritance of C ++ can be completed through multiple interfaces; category is a category, which is generally well classified, the method that uses category to override classes is only valid for this category and does not affect the relationship between other classes and the original classes.

 

2. # What is the difference between import and # include? What is the difference between @ class and # import <> and # import?

# Import is the keyword used to import the objective-C header file. # include is the keyword used to import the C/C ++ header file. If you use the # import header file, it is automatically imported only once without repeated import, it is equivalent to # include and # pragma once; @ Class tells the compiler about the declaration of a class. Only when executed can we view the implementation file of the class, which can solve the mutual inclusion of header files; # import <> is used to include the system header file, and # import "is used to include the user header file.

 

3. What are the functions of attributes readwrite, readonly, assign, retain, copy, and nonatomic?

Readwrite is a readable and writable feature. When you need to generate the getter method and setter method

Readonly is a read-only feature that only generates the getter method and does not generate the setter method. You do not want the attribute to change outside the class.

Assign is a value assignment feature. The setter method assigns input parameters to instance variables. Only variables are set;

Retain indicates that the property is held. The setter method retains the input parameter first and then assigns a value. The retaincount of the input parameter will be + 1;

Copy indicates the value assignment feature. The setter method copies the input object. When a new variable is required.

Nonatomic non-atomic operations determine whether the setter getter generated by the compiler is an atomic operation. Atomic indicates multi-thread security. nonatomic

4. Write a setter method to complete @ property (nonatomic, retain) nsstring * name, and write a setter method to complete @ property (nonatomic, copy) nsstring * Name

- (void) setName:(NSString*) str{[str retain];[name release];name = str;}- (void)setName:(NSString *)str{id t = [str copy];[name release];name = t;}

 

5. For the statement nsstring * OBJ = [[nsdata alloc] init]; what types of objects are used for OBJ during compilation and runtime?

It is an nsstring type during compilation, and an object of the nsdata type during runtime.

6. What are the common object-C data types? What is the difference between them and C's basic data types? Such as nsinteger and int

The Data Types of Object-C include nsstring, nsnumber, nsarray, nsmutablearray, and nsdata. These are all classes. After the object is created, the basic data type of C language is int, only a certain byte of memory space is used to store values. The nsnumber of Object-C contains the nsobject method of the parent class and the nsnumber method, which can complete complex operations.

 

7. What are the features of the object declared by ID?

The object declared by ID has the runtime feature, that is, it can point to any type of objcetive-C object;

 

8. How does objective-C manage the memory? What are your opinions and solutions?

Objective-C memory management mainly includes three methods: arc (Automatic Memory count), Manual memory count, and memory pool.

 

9. What are the principles of memory management? According to the default rule. objects generated by those keywords

Need to be manually released? How can we effectively avoid Memory leakage when combined with property?

Who applies and who releases

Complies with the use principles of cocoa touch;

Memory Management mainly needs to avoid "premature release" and "Memory leakage". For "premature release", note that when setting the @ property feature, you must use the feature keyword. For "Memory leakage ", be sure to apply for release and be careful.

The keywords alloc or new generated objects need to be manually released;

Set the correct Property and release the retain in the appropriate place,

 

10. How to test the performance of iOS devices?

Profile-> instruments-> time profiler

11. Check the following program. What will the first nslog output? What is the retaincount of str? What about the second and third? Why?

=======================================================NSMutableArray* ary = [[NSMutableArray array] retain];NSString *str = [NSString stringWithFormat:@"test"];[strretain];[aryaddObject:str];NSLog(@"%@%d",str,[str retainCount]);[strretain];[strrelease];[strrelease];NSLog(@"%@%d",str,[str retainCount]);[aryremoveAllObjects];NSLog(@"%@%d",str,[str retainCount]);=======================================================

STR retaincount creation + 1, retain + 1, add array auto + 1

3

Retain + 1, release-1, release-1

2

Delete all objects in the array. All objects in the array are automatically-1.

1

12. What is the thread creation method in Object C? What is the method for executing code in the main thread? If you want to delay code execution, what is the method?

There are three ways to create a thread: Use nsthread to create a thread, use GCD dispatch, use nsoperation as a subclass, and then add it to nsoperationqueue; execute code in the main thread by running mselecw.mainthread, if you want to run code in a delayed manner, you can use javasmselector: onthread: withobject: waituntildone:

13. describes how to implement the MVC development mode in the ios sdk.

MVC is a model, attempt, and control development mode. for iOS SDK, all views are on the view layer, which should be independent of the model layer and controlled by the view control layer. All user data is a model layer, which should be independent of the view. All viewcontrollers are control layers that control views and access model data.

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.