iOS programmer interview questions to pay attention to

iOS programmer interview questions to pay attention to

[[121698]]

1. What is an autorelease pool and how does it work?

When you send an autorelease message to an object, Cocoa puts a reference to the object into the specified autorelease pool. It is still a valid object, so other objects in the scope defined by the autorelease pool can send messages to it. When the program executes to the end of the scope, the autorelease pool is released, and all objects in the pool are released.

2. Talk about the static keyword

(1) The scope of a static variable in a function is the function body. Unlike auto variables, the memory of the variable is only allocated once.

Therefore, its value will remain the same as the last time it is called next time;

(2) Static global variables within a module can be accessed by functions within the module, but cannot be accessed by other functions outside the module;

(3) A static function in a module can only be called by other functions in the module. The scope of use of this function is limited to the declaration.

within its module;

(4) The static member variables in a class belong to the entire class, and there is only one copy for all objects of the class;

(5) The static member function in a class belongs to the entire class. This function does not receive the this pointer and can therefore only access the static member variables of the class.

3. What is a single instance?

Some classes in the Foundation and Application Kit frameworks allow you to create only singleton objects, that is, the only instance of these classes in the current process. For example, the NSFileManager and NSWorkspace classes are used on a per-process basis as singleton objects. When you ask these classes for an instance, they pass you a reference to the singleton instance, and then allocate and initialize the instance if it doesn't already exist. The singleton object acts as a control center, directing or coordinating the various services of the class. If a class conceptually has only one instance (such as

NSWorkspace), you should create a single instance instead of multiple instances; if there may be multiple instances someday in the future, you can

To use a singleton instance mechanism instead of factory methods or functions.

4. Talk about Objective-C, what are its advantages and disadvantages

Objc advantages:

1) Categories

2) Posing

3) Dynamic recognition

4) Indicator calculation

5) Flexible message delivery

6) Not an overly complex C derivative

7) Objective-C and C++ can be mixed programming

insufficient:

1) No support for namespaces

2) Operator overloading is not supported

3) Multiple inheritance is not supported

4) Using dynamic runtime types, all methods are function calls, so many compile-time optimization methods cannot be used (such as inline functions, etc.), and the performance is poor.

5. What is the difference between #import and #include? What does @class stand for?

@class is generally used when you need to declare an instance variable of the class in the header file. #import is still needed in the m file.

The advantage of #import over #include is that it does not cause duplicate inclusion.

6. What is the difference between a thread and a process?

Both processes and threads are the basic units of program execution recognized by the operating system, and the system uses these basic units to achieve concurrency for applications.

The main difference between processes and threads is that they are different ways of managing operating system resources. Processes have independent address spaces. When a process crashes, it will not affect other processes in protected mode. Threads are just different execution paths in a process. Threads have their own stacks and local variables, but there is no separate address space between threads. If a thread dies, the entire process dies. Therefore, multi-process programs are more robust than multi-threaded programs, but when switching processes, they consume more resources and are less efficient. However, for some concurrent operations that require simultaneous execution and share certain variables, only threads can be used, not processes.

7. Memory management of Object-C?

1. When you create an object using the new, alloc, and copy methods, the object's retention counter value is 1. When you no longer use the object, you are responsible for sending a release or autorelease message to the object. In this way, the object will be destroyed at the end of its life.

2. When you obtain an object through any other method, it is assumed that the object's retain counter value is 1 and it has been set to be automatically released. You do not need to do anything to ensure that the object is cleaned up. If you plan to own the object for a period of time, you need to retain it and ensure that it is released when the operation is completed.

3. If you retain an object, you need to (eventually) release or automatically release the object. You must keep the number of times the retain method and the release method are used equal.

8. What are the functions of the attributes readwrite, readonly, assign, retain, copy, and nonatomic, and in what situations are they used?

readwrite is a readable and writable feature; when getter and setter methods need to be generated

readonly is a read-only attribute. Only getter methods will be generated, not setter methods. You don't want the attribute to be changed outside the class.

Assign is an assignment feature, the setter method assigns the passed parameter to the instance variable; only when setting the variable;

retain means holding feature. The setter method will retain the passed parameter first and then assign a value. The retaincount of the passed parameter will be increased by 1.

copy indicates the assignment feature. The setter method copies the passed object; when a completely new variable is required.

nonatomic non-atomic operation, determines whether the setter getter generated by the compiler is an atomic operation. atomic means multi-threaded safety, generally use nonatomic

<<:  Eleven ways to make your IT career bottleneck-free

>>:  Testing experience of Swift framework on Xcode 6

Recommend

How do content-based products go global from Douyin, Toutiao, UC Headlines, etc.?

2018 marks a new stage for China’s Internet going...

User Growth: Why isn’t your user base growing?

The changes of the times and channels will bring ...

The First Chaos in History_Liu Mang Version Episodes 001-302 (Audio-Liu Mang)

The First Chaos in History_Liu Mang Version Episo...

Come, choose a dinosaur as a "mount" ~

Excerpted from: "Inside and Outside the Clas...

How to analyze live streaming traffic!

There are two topics today. The first one is &quo...

How easy is it to “misjudge” yourself?

© neurofeedback Leviathan Press: There is a sayin...

How I became number one on the App Store

Happiness comes too suddenly? Others say that our...

Qvod officially returns to the familiar taste but not the original formula

Qvod, I believe everyone is very familiar with it...

Super strategy for operation and promotion of the new version of APP in 2016!

In 2016, mobile Internet startup products face mo...

Deloitte Consulting: Generative Artificial Intelligence Report, Q2 2024

Value creation The proportion of organizations re...

How to improve user retention through game mechanics?

According to the "2020 China Game Industry R...