iOS Development questions (i)

Source: Internet
Author: User

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是Objective-C keyword to import the header file, #include是C/c++ import header file keyword, using #import header file will automatically import only once, will not repeat the import, equivalent to # 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 the copy attribute, and the setter method copies the incoming object to a copy; When a new variable is needed completely.

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

[CPP]View Plaincopyprint?
    1. -(void) SetName: (nsstring*) str
    2. {
    3. [Str retain];
    4. [Name release];
    5. name = str;
    6. }
    7. -(void) SetName: (NSString *) str
    8. {
    9. ID t = [str copy];
    10. [Name release];
    11. name = t;
    12. }

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?

[CPP]View Plaincopyprint?
  1. =======================================================
  2. nsmutablearray* ary = [[Nsmutablearray array] retain];
  3. NSString *str = [nsstring stringwithformat:@"test"];
  4. [Strretain];
  5. [ARYADDOBJECT:STR];
  6. NSLog (@"%@%d", Str,[str Retaincount]);
  7. [Strretain];
  8. [Strrelease];
  9. [Strrelease];
  10. NSLog (@"%@%d", Str,[str Retaincount]);
  11. [Aryremoveallobjects];
  12. NSLog (@"%@%d", Str,[str Retaincount]);
  13. =======================================================

Str Retaincount creates +1,retain+1, joins the array automatically +1

3

Retain+1,release-1,release-1

2

Array removes all objects, all objects within the array automatically-1

1

What is the method for creating threads in Object C? If you execute code in the main thread, what is the method? What if you want to delay the execution of code and methods?

There are three ways to create a thread: Use Nsthread to create, use GCD dispatch, use a subclass nsoperation, and then add it to Nsoperationqueue; Execute code on the main thread. The method is Performselectoronmainthread, if you want to delay the execution of code can be used PerformSelector:onThread:withObject:waitUntilDone:

13. Describe how to implement the MVC development model in the iOS SDK

MVC is a model, an attempt to control the development pattern, and for the iOS SDK, all views are view layers, which should be independent of the model layer and controlled by the view control layer. All user data is the model layer and should be independent of the view. All Viewcontroller are control layers, which are responsible for controlling the view and accessing the model data.

iOS Development questions (i)

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.