iOS face question Daquan 56-65

Source: Internet
Author: User

What is 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能防止同一个文件被包含多次

The 2> @class simply declares a class name and does not contain a complete declaration of the class; @class can also solve the problem of loop containment

3> #import <> used to include the file that comes with the system, #import "" to include the custom file

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

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

2> readonly: Generate declarations and implementations of Get methods only

The implementation of the 3> Assign:set method is a direct assignment for the basic data type

The implementation of the 4> Retain:set method is the release old value, retain new value, for OC object type

The implementation of the 5> Copy:set method is the release 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)

58. Write a setter method to complete @property (nonatomic,retain) nsstring *name, write a setter method for completing @property (nonatomic,copy) NSString *na Me.

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];

}

}

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

1> compile-time is nsstring type

2> Runtime is NSData type

60. What are the common object-c data types, and what is the difference between the basic data types of C?

1> commonly used OC types: NSString, Nsarray, Nsdictionary, NSData, NSNumber, etc.

2> OC objects need to manage memory manually, C's basic data type does not need to manage memory

What is the nature of the variable with ID declaration?

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

Objective-c How to manage memory, say your opinion and solution?

1> Each object has a reference counter, the counter for each new object is 1, and when the object's counter is reduced to 0 o'clock, it is destroyed

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

3> can also manage memory through Autorelease pool

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

63. What are the several principles of memory management? 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> as long as the alloc, copy, and new methods are called to produce a new object, it must be called at the end of the release or autorelease

2> whenever retain is called, it must be called at the last release or Autorelease

3> @property If you use Copy or Retian, you need to do a release operation on the attributes that you no longer use.

4> If arc is used, another discussion

64. Look at the following program, 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]);

Results: 3, 2, 1

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

1> Ways to create threads

    • Nsthread
    • Nsoperationqueue and Nsoperation
    • GCD

2> executing code in the 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 Daquan 56-65

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.