iOS comprehensive face question 1

Source: Internet
Author: User

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

2. What is the function of attribute 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 proxy

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)

3, write a setter method for completing @property (nonatomic,retain) nsstring *name, write a setter method to complete @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];

}

}

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

1> compile time is NSString

2> Runtime is NSData type

5. What is the difference between the data types of common object-c and 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

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

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

7, objective-c How to memory management, say your views and solutions?

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

8. 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:];

9, object-c have multiple inheritance? If not, what's the substitute for??

1> OC is single inheritance, no multiple inheritance

2> can sometimes replace multiple inheritance with classifications and protocols

10. Does object-c have a private method? What about private variables??

1> OC does not have a @private-like modifier to modify the method, as long as it is written in the. h file, which is the public method

2> can use class extensions (Extension) to add private methods and private variables

11. What is the meaning of the keyword const?

const int A;

int const A;

const int *a;

int const *A;

int * const A;

int const * const A;

1> the first two functions are the same: A is a constant integer number

2> third to fourth means a is a pointer to a constant integer number (the integer number is not modifiable, but the pointer can)

3> Fifth means: A is a constant pointer to an integer number (the integer number pointed to by the pointer can be modified, but the pointer is not modifiable)

4> last means: A is a constant pointer to a constant number (the integer number pointed to by the pointer is not modifiable and the pointer is not modifiable)

12, the role of static?

The 1> static modifier is an intrinsic function that can only be called in this file, and other files cannot be called

All variables of the 2> static modifier are an internal variable that can only be used in this file and cannot be used by other files

3> static modified local variables are initialized only once and the memory is reclaimed when the program exits

13. What are the differences between threads and processes?

1> an application corresponds to a process, a process helper occupies a piece of storage space

2> to perform a task in a process, you must turn on the thread, and a thread represents a task

3> allows multiple threads to be opened in one process, that is, performing multiple tasks at the same time

14, heap and stack of the difference??

The memory of the 1> heap space is dynamically allocated, typically storing objects, and requires manual memory release

The memory of the 2> stack space is automatically allocated by the system, usually storing local variables, and does not need to manage the memory manually

15, why a lot of built-in classes, such as TableView's Delegate property is assign is not retain??

1> TableView Agent is generally the controller that it belongs to, the controller will do a retain operation of its internal view

2> assumes that TableView also do a retain operation on the agent (Controller), then there is a cyclic retain problem

16. When defining attributes, what is the use of copy, assign, retain??

1> copy:nsstring, block and other types

2> Assign: Non-OC object type, base data type (two objects referencing each other, one end with retain, one end with assign)

3> Retain:oc Object Type

17, when the Viewcontroller Loadview, Viewdidload, viewdidunload are called, when the custom Viewcointroller in these functions should do what work?

1> Loadview

      • When using the controller's view for the first time, the Loadview method is called to create the view
      • In general, customize the view here

2> Viewdidload

      • Called when the controller's view is created, that is, after Loadview
      • It is common to add child controls, initialize data

3> Viewdidunload

      • Called when the controller's view is destroyed because of a memory warning
      • Usually here to recycle the interface-related resources (the interface will be destroyed, and interface-related resources must not be)

18, how to understand MVC, in the cocoa How is MVC implemented??

1> M:model, model, encapsulated data

2> V:view, view interface, responsible for displaying data

3> C:controller, CONTROLLER, responsible for providing data (Model) to the interface (View)

19, self. What's the difference with self->?

1> self. is to call the Get method or set method

2> Self is the current itself and is a pointer to the current object

3> self-> is a direct access member variable

20.

iOS comprehensive face question 1

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.