iOS face question 6.30 summary

Source: Internet
Author: User

More and more people are investing in the iOS industry, but as a student who just graduated from school, we have no experience. or little experience. But it doesn't stop us from being enthusiastic about Apple and wants to put it into the development of iOS. And as the first step into the business, we have to attend the interview. We may encounter many problems during the interview. So I want to summarize the questions I might ask in the interview.

One What's the difference between #import and #include,@class? # What's the difference between import<> and #import?

 1. #import和 # include can contain the contents of a file completely, #import能防止同一个文件被包含多次

2, @class just declare a class name, will not contain the full declaration of tears; @class can also solve the problem of loop containment

3, #import <> used to include the system comes with the file, #import "" to include the customization of the file

Second,PropertiesReadWrite,ReadOnly,Assign,retain,Copy,nonatomicWhat is the role of each, in that case?

1, ReadWrite: Simultaneous generation of the Get method and the set method declaration and implementation

2, ReadOnly: Generate only the Declaration and implementation of the Get method

3, the implementation of the Assign:set method is just a direct copy, for the basic data type

4, Retain:set method implementation is release old value, Rerain new value, for OC object

5, Copy;set Method realizes is relase old value, copy new value, for NSString, block and other types

6. nonatomic: Non-atomic, The implementation of the set method is not locked (higher than atomic performance)

Third,Write a setter method for completing the @property (nonatomic,retain) NSString *name, and write a setter method for completing @property (nonatomic,copy) nsstring *name.

  

1, @property (nonatomic, retain) NSString *name;

-(void) SetName: (NSString *) name

{

if (_name! = name) {

[_name release];

_name = [name retain];

}

}

2, @property (nonatomic, copy) NSString *name;

-(void) SetName: (NSString *) name

{

if (_name! = name) {

[_name release];

_name = [name copy];

}

}

Four,For statement nsstring*obj = [[NSData alloc] init]; , what is the type of compile-time and run-time obj respectively?

1, compile the time is NSString type

2, when the operation is the NSData type

V. What are the common OC data types? What is the difference between the basic data types of C and

1, commonly used OC type: NSString, Nsarray, Nsdictionary, NSData, nsnumber, etc.

2. OC objects require manual memory management (MRC mode), C data types do not require memory management

Vi. What are the characteristics of the variables declared by ID?

The variable that the ID declares can point to any OC object

SevenObjective-c How to manage the memory, say your opinion and solve the method?

1, each object has a reference count, each new object reference count is 1, when the object's counter minus 0, this time the object will be destroyed

2, through the retain can let the object counter +1,release can let the object counter-1

3. You can also manage memory by automatically releasing the pool

4. If arc is used, the compiler will automatically generate code to manage memory

Eight, memory management of a few principles when what? Follow the default rules. Which methods generate objects that need to be released manually? How to effectively avoid memory leaks when combined with property?

1. Whenever a alloc, copy, or new method is called to produce a fresh object, it must be called at the last Autorelease

2, as long as you call the retain, must be called at the last Autorelease

3, @property If you use copy or retain, you need to do a release operation for attributes that are no longer used

4, when the use of Arc mechanism, will be additional discussion

Nine, see the following procedure, three times nslog will output what? Why?

  

nsmutablearray* ary = [[Nsmutablearray array] retain];

NSString *str = [nsstring stringwithformat:@ "test"]; 1

[Str retain]; 2

[Ary Addobject:str]; 3

NSLog (@ "%d", [str retaincount]);

[Str retain]; 4

[STR release]; 3

[STR release]; 2

NSLog (@ "%d", [str retaincount]);

[Ary Removeallobjects]; 1

NSLog (@ "%d", [str retaincount]);

The result of the output is 3, 2, 1

What is the method for creating threads in OC? If you specify to the main thread to execute code? How to delay code execution?

1. Ways to create Threads

    • Nsthread
    • Nsoperationqueue and Nsoperation
    • GCD

2. Execute code in main thread

    • [Self performSelectorOnMainThread:withObject:waitUntilDone:];
    • [Self performselector:onthread:[nsthread mainthread] Withobject:waituntildone:];
    • Dispatch_async (Dispatch_get_main_queue (), ^{

});

3. Delay execution

    • Double delayinseconds = 2.0;

dispatch_time_t poptime = Dispatch_time (Dispatch_time_now,

(int64_t) (Delayinseconds * nsec_per_sec));

Dispatch_after (Poptime, Dispatch_get_main_queue (), ^ (void) {

});

    • [Self performSelector:withObject:afterDelay:];
    • [Nstimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:];

iOS face question 6.30 summary

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.