iOS development interview High frequency problem

Source: Internet
Author: User
Tags shallow copy

iOS development interview High-frequency questions, interview no longer crazyDirectory front-end technology May 4, 2016

For the students who are interviewing for iOS development, they may have seen a lot of questions. But there are a lot of questions on the net, but there is no focus, and some are too few. Today's small series to everyone to organize a number of more important and often asked questions, a total of 20, in half an hour can be read.

1. Can the class of object-c inherit multiple? Can I implement more than one interface? What is category? How do you rewrite a class in a way that inherits or classifies well?

A: The class of object-c is not multiple inheritance; multiple interfaces can be implemented, and multiple inheritance of C + + can be accomplished by implementing several interfaces; Category is the class, the general situation with good classification, with category to rewrite the method of the class, only valid for this category, will not affect the other classes and the original class relationship.

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

A: #import是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, equivalent to # include and #pragma once;@ Class tells the compiler the declaration of a class, when executed, only to see the implementation of the class file, you can resolve the header file of each other, #import <> 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?

For:

1). ReadWrite is a readable writable feature; When you need to generate getter and setter methods

2). 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

3). Assign is an assignment attribute, the setter method assigns the passed-in parameter to the instance variable, and only when the variable is set;

4). Retain means holding characteristics, setter method will pass in the parameters of the first reservation, and then assign value, the Retaincount of the incoming parameter will be +1;

5). Copy represents an assignment attribute, and the setter method copies the incoming object to a copy; When a new variable is required.

6). nonatomic Non-atomic operation, determines whether the compiler-generated setter getter is an atomic operation, atomic represents multithreading security, general use Nonatomic

4. For statement nsstring*obj = [[NSData alloc] init]; What type of object does obj have at compile time and run time, respectively?

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

5. What is the difference between the data types of common object-c and the basic data types of C? such as: Nsinteger and int

A: Object-c data type has nsstring,nsnumber,nsarray,nsmutablearray,nsdata and so on, these are class, created is the object, and C language basic data type int, only a certain byte of memory space , for storing values; Nsinteger is a 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 6.id?

A: The object declared by Id has the runtime characteristics, which can point to any type of objcetive-c object;

7. What is the difference between an atom (atomic) and a non-atomic (non-atomic) attribute?

For:

1). Atomic provides multithreading security. is to prevent it from being read by another thread when the write is incomplete, resulting in a data error

2). Non-atomic: In the environment in which it manages memory, the accessor that is parsed retains and automatically releases the returned value, and if Nonatomic is specified, the accessor simply returns the value.

8. What are some of the principles of memory management? Follow the default rules. What do those keyword-generated objects need to be released manually? How can I effectively avoid memory leaks when combined with property?

Answer: 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,

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

Answer: profile-> Instruments->time Profiler

What is the method for creating threads in Object C? What is the method if you execute code in the main thread? What is the method if you want to defer execution of code?

A: 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:

11 Shallow copy and deep copy the difference?

A: Shallow copy: Copies only pointers to objects, not the reference object itself.

Deep copy: Copies the reference object itself.

That means I have an A object, after copying a copy to get A_copy object, for shallow copy, A and a_copy point to the same memory resource, copy is just a pointer, the object itself resources

There is only one copy, so if we do a modification to a_copy, then we find that the object referenced by A is also modified, which violates the idea of copying copies. Deep replication is a good idea, and there's an in-memory

Two copies of the independent object itself.

Using a friend on the Internet, the popular words will be:

Shallow copy is like you and your shadow, you are finished, your shadow is finished

Deep replication is like you and your clones, you're screwed, your clones are alive.

12. What is the difference between inheritance and category in implementation?

A: Category can add new methods without knowing, without changing the original code, can only be added, cannot delete changes, and if the category and methods in the original class produce name conflicts, the class overrides the original method because the category has a higher priority.

There are 3 main functions of the category:

1). Spread the implementation of the class across multiple different files or multiple different frameworks.

2). Create a forward reference to the private method.

3). Add an informal agreement to the object.

Inheritance can add, modify, or Delete methods, and can add properties.

13. Differences between categories and class extensions.

A: The difference between category and extensions is that the latter can add attributes. In addition, the method that the latter adds must be implemented.

Extensions can be thought of as a private category.

14. What is the role of the agent?

A: The purpose of the agent is to change or transfer the control chain. Allows a class to be notified to other classes at certain times without having to obtain pointers to those classes. Can reduce the complexity of the frame.

On the other hand, a proxy can be understood as a similarity to the callback listener mechanism in Java.

the the type can be modified and not modifiable in. OC.

A: You can modify a collection class that is not modifiable. My personal simple understanding is that you can add changes dynamically and not add changes dynamically.

Like Nsarray and Nsmutablearray. The former in the initialization of the memory control is fixed immutable, the latter can be added, etc., you can dynamically request new memory space.

What is the garbage collection mechanism for OC?

A: OC2.0 has garbage collection, but the iOS platform is not available.

Generally we know that objective-c is manual for memory management, but it also has an auto-release pool.

But most of the information, it seems not to be confused with the arc mechanism.

- . What is deferred loading?

Answer: Lazy mode, only when the use of the time to initialize.

Can also be understood as delayed loading.

I think the best is also the simplest of a sample is the TableView in the picture loading shows.

A delay load, to avoid excessive memory, an asynchronous load, to avoid thread congestion.

18. When to use Nsmutablearray, when to use Nsarray?

A: When the array is running in the program, it needs to be constantly changing, using the Nsmutablearray, when the array is initialized, it will no longer change, use Nsarray. It should be noted that the use of Nsarray only indicates that the array does not change at run time, i.e. it cannot add and remove elements to the Nsaarry array, but does not indicate that the contents of elements within its array cannot be changed. Nsarray is thread-safe, Nsmutablearray is not thread-safe, and multithreading is used to nsmutablearray needs attention.

19. Which methods of class nsobject are often used?

A: NSObject is the base class of Objetive-c, which is composed of NSObject class and a series of protocols.

Class methods Alloc, Class, Description object Methods init, Dealloc, –performselector:withobject:afterdelay: etc. are often used

- How do I save data in the iphone app?

A: There are several preservation mechanisms:

1). Save on the server via the Web service

2). Save the object in a file by nscoder the curing mechanism

3). Save in the file database via SQLite or CoreData

Before the interview look at the question although can help you a hand, but the most important thing is usually to improve their technical ability. Wheat wish everyone can find a good job, worthy of their own efforts.

iOS development interview High frequency problem

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.