IOS Face Test series

Source: Internet
Author: User

With the development of iOS platform for the increase of the position, the written test, interview more and more "routines", here I summed up some interview questions, most of the basic knowledge of objective-c, suitable for interviewing new people, the answer is my own answer, inaccurate place, welcome to point out.

1. Can the Object-c class inherit multiple classes? Can I implement multiple interfaces? What is category? Is it better to rewrite a class in a way that inherits or classifies? Why?

The class of object-c cannot inherit multiple, can implement multiple interfaces, can accomplish multiple inheritance of C + + by implementing several interfaces; category is a class, the general classification is good, the category to rewrite the method of class, only for this category valid, Does not affect the relationship of other classes to the original class.

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

#import is the 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, the equivalent of # 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.

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

ReadWrite is a readable and 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

4. Write a setter method to complete @property (nonatomic,retain) nsstring *name, write a setter method for completing @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 statement nsstring*obj = [[NSData alloc] init]; What type of object does obj have at compile time and run time, respectively?

Compile-time is the type of nsstring; runtime is an object of type NSData

6. 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

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, Used to store numeric values; Nsinteger is the 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 7.id?

An Id-declared object has a runtime attribute, which can point to an object of any type of objcetive-c;

8.objective-c How to manage the memory, say your opinion and solve the method?

OBJECTIVE-C memory management has three main ways of Arc (automatic memory count), manual memory count, memory pool.

9. What are the several principles of memory management? Follow the default rules. Those keyword-generated objects

Need to be released manually? How to effectively avoid memory leaks when combined with property?

Who applies, who releases

Follow the cocoa touch usage principles;

Memory management mainly to avoid "premature release" and "Memory Leak", for "premature release" need to pay attention to the @property setting characteristics, must use the keyword to the attribute, for "memory leak", must apply for the release, be careful.

The object generated by the keyword Alloc or new needs to be released manually;

Set the correct property properties, for retain need to be released in the appropriate place,

10. How do I perform a performance test on my iOS device?

profile-> Instruments->time Profiler

11. See the following program, what will the first nslog output? What is the retaincount of STR at this time? A second and a 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]); =======================================================

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.