1. What are the differences and connections between iOS threads and processes?

Process and thread are the basic unit of the program run by the operating system. The system uses the basic unit to realize the system’s concurrency to the application.

The main difference between procedures and threads is that they are different ways of managing operating system resources. Processes have independent address Spaces, a crash of one process in protected mode does not affect other processes, and threads are just different execution paths within a process. Thread has its own stack and local variables, but there is no separate address space between threads, a thread dead is equal to the whole process dead, so multi-process procedures than multithreaded procedures robust, but in the process switch, the cost of resources is larger, the efficiency is poor. However, for concurrent operations that require simultaneous and variable sharing, only threads, not processes, can be used.

As a developer, it’s especially important to have a learning atmosphere and a networking community, and this is one of my iOS development networking groups:130595548, whether you are small white or big cattle are welcome to enter, let us progress together, common development! (The group will provide some free study books collected by the group owner and hundreds of interview questions and answers documents for free!)

2. How does iOS find the most appropriate controls to handle events?

Can I receive touch events? Is the touch point on your body? Iterate through the child control from back to front, repeating the previous two steps if there is no child control that meets the criteria, then it is best to process itself

3. The iOS static keyword is used.

(1) Static variables are used in the function body. Unlike auto variables, the memory of this variable is allocated only once.

So its value remains the same the next time it is called;

(2) Static global variables can be accessed by functions inside the module, but not by other functions outside the module.

(3) Static functions in a module can only be called by other functions in the module. The scope of this function is restricted to declarations

Inside its module;

(4) The static member variable is owned by the entire class. There is only one copy of all objects in the class.

(5) The static member function in a class is owned by the entire class. This function does not receive the this pointer, so it can only access the static member variable of the class.

4. Functions and common attributes of iOS UIEvent object?

Each time an event is generated, a UIEvent object is generated

UIEvent: called an event object, which records the time and type of the event:

//@property(nonatomic, readOnly) UIEventType type; //@property(nonatomic,readonly) UIEventSubtype subtype; @property(nonatomic,readonly) NSTimeInterval timestamp; UIEvent also provides a way to get a touch object (UITouch) on a viewCopy the code

When is loadView, viewDidLoad, viewDidUnload called? What do you do in these functions when you’re customizing a ViewController?

ViewDidLoad is called when the view is initialized from the NIB file, loadView is called when the view of the controller is nil. This method is called when implementing the view programmatically. The View controller registers memory warning Notification by default. ViewDidUnload is called when any view of the View controller is not used. This is where you implement the view release of the retain, if it’s the IBOutlet view property of the retain you don’t release it here,IBOutlet will release it.

5. The advantages and disadvantages of Object-C?

Objc advantages:

  1. Cateogies

  2. Posing

  3. Dynamic identification

  4. Index calculation

5) Flexible messaging

  1. Not an overly complex C derivative language

  2. Objective-c and C++ can be mixed programming

Disadvantages:

  1. Namespaces are not supported

  2. Operator overloading is not supported

3) Multiple inheritance is not supported

4) With dynamic runtime types, all methods are function calls, so many compile-time optimization methods are not used. (such as inline functions), poor performance.

6. What is the difference between iOS references and Pointers?

1. References must be initialized, Pointers not. 2. A reference cannot be changed after initialization. A pointer can change the object to which it refers. 3. There is no reference to a null value, but a pointer to a null value.

7. What is the difference between iOS heap and stack?

Management mode: for the stack, it is automatically managed by the compiler without our manual control; In the case of the heap, the release is controlled by the programmer, leading to memory leaks.

Application size:

Stack: Under Windows, a stack is a low-address data structure, a contiguous area of memory. The address at the top of the stack and the maximum size of the stack are specified by the system. Under WINDOWS, the stack size is 2M (or 1M). If the stack size exceeds the available space, overflow will be prompted. Therefore, less space can be obtained from the stack.

Heap: A heap is a data structure that extends to a high address and is a discontinuous area of memory. This is because the system uses a linked list to store the free memory address, which is naturally discontinuous, and the traversal direction of the list is from low address to high address. The size of the heap is limited by the amount of virtual memory available in the computer system. Thus, the heap is more flexible and larger.

Fragmentation problem: For the heap, frequent new/ DELETE will inevitably lead to discontinuous memory space, resulting in a large amount of fragmentation, making the program inefficient. This is not a problem with stacks, because stacks are first in, last out queues, and they are so one-to-one that it is never possible for a block of memory to eject from the middle of the stack

Allocation: The heap is dynamically allocated, there is no statically allocated heap. There are two types of stack allocation: static allocation and dynamic allocation. Static assignment is done by the compiler, such as assignment of local variables. Dynamic allocation is done by the Alloca function, but stack dynamic allocation is different from heap dynamic allocation, which is released by the compiler without manual implementation.

Allocation efficiency: the stack is a data structure provided by the machine system, and the computer provides support for the stack at the bottom: special registers are allocated to store the address of the stack, and special instructions are executed for pushing and removing the stack, which determines the high efficiency of the stack. The heap is provided by the C/C++ library, and its mechanism is quite complex.

8. When to use Delegate and when to use Notification?

Delegate for one-to-one relationships, and Reciever can return a value to the Sender, notification for One-To-one /many/ None, and Reciever can’t return a value to the sender. So, the delegate is used for the sender that wants to receive a function from reciever, and the notification is used to notify multiple Objects of an event.

9. What are the functions and common attributes of the iOS UITouch object?

When the user touches the screen with a finger, a UITouch object is created that is associated with the finger, one for each finger

UITouch features:

It holds information about the finger, such as the position, time, and phase of the touch. As the finger moves, the system updates the same UITouch object so that it stays at the same touch position. When the finger leaves the screen, the system destroys the common properties of the corresponding UITouch object

/ / touch produced by window @ property (nonatomic, readonly, retain) UIWindow * window; / / touch produce view of @ property (nonatomic, readonly, retain) UIView * view; @Property (nonatomic, readOnly) NSUInteger tapCount; @property(nonatomic, readOnly) NSUInteger tapCount; @property(nonatomic,readonly) NSTimeInterval timestamp; @property(nonatomic, readOnly) UITouchPhase Phase;Copy the code

Common methods of UITouch

// The value returned is the position of the touch on the view // the position returned is for the view's coordinate system (starting from the top left corner of the view (0, 0)) // If the view argument is passed nil, Returns the position of the touch point in UIWindow - (CGPoint)locationInView:(UIView *)view; // this method records the position of the previous touch point - (CGPoint)previousLocationInView:(UIView *)view;Copy the code

10. Object-c memory management?

If you create an object by allocating and initializing it (such as [[MyClass Alloc] init]), you own the object and are responsible for releasing it. This rule also applies when using NSObject’s convenience method new.

If you copy an object, you own the copied object and are responsible for releasing it.

If you keep an object, you partly own it and need to release it when it is no longer in use.

Conversely, if you receive an object from another object, you do not own it and should not release it (there are a few exceptions to this rule)

11. What is an iOS singleton instance?

Some classes in the Foundation and Application Kit frameworks only allow the creation of singleton objects, which are unique instances of those classes in the current process. For example, the NSFileManager and NSWorkspace classes are used to instantiate singleton objects on a process-based basis. When an instance is requested from these classes, they pass you a reference to a single instance, which is allocated and initialized first if it doesn’t already exist. Singleton acts as a control center, directing or coordinating the various services of the class. If the class is conceptually only one instance (such as NSWorkspace), a singleton instance should be generated, rather than multiple instances; If you might someday have multiple instances, you can use the singleton mechanism instead of factory methods or functions.

12. What is the iOS class factory method?

Class factory methods are implemented to provide convenience to customers by combining allocation and initialization in one step, returning the created object, and automatically releasing it. These methods are of the form + (type)className… Where className does not include any prefix.

The factory approach may be about more than just convenience. They not only combine allocation and initialization, but also provide allocation information for the initialization process. Another purpose of the class factory method is to enable classes (such as NSWorkspace) to provide singleton instances. Although the init… Methods can confirm that only one instance of a class exists each time the program runs, but they need to allocate a “live” instance first and must then release that instance, while factory methods can avoid blindly allocating memory for objects that may not be useful.

13. Can a pointer be volatile? Explain why.

Yes. Although it’s not very common. An example is when a service subroutine fixes a pointer to a buffer.

14. Limitations of the iOS category?

There are two limitations:

(1) New instance variables cannot be added to the class. The class has no place to hold instance variables.

(2) Name conflict, that is, when the method in the category conflicts with the original class method name, the category has a higher priority. The class method completely replaces the initial method and can no longer be used.

The limitation of not being able to add instance variables can be solved using dictionary objects

15. What is an iOS key-value and what is the key-path?

The nature of the model is specified by a simple key (usually a string). Views and controllers use keys to find the corresponding property value. In a given entity, all values of the same attribute have the same data type. Key-value coding is used for such lookups – it is a mechanism for indirectly accessing object properties.

A key path is a string of dot-delimited keys used to specify a concatenated sequence of object properties. The properties of the first key are determined by the preceding properties, and the values of each subsequent key are also relative to the preceding properties. Key paths allow you to be model-independent

The way the implementation is implemented specifies the nature of the relevant object. With key paths, you can specify a path in an object graph at any depth to point to a specific property of the object in question.

16. What does the iOS category do?

Categories have three main functions:

(1) Split the implementation of the class into multiple different files or multiple different frameworks.

(2) Create forward references to private methods.

(3) Add informal protocols to objects.

17. What should I pay attention to when using sprintf,strcpy,memcpy?

Strcpy is a string copy function whose prototype is strcpy(char DST, ct char * SRC);

Copy a string that starts with SRC into the memory that starts with DST and ends with ‘\0’. Since the length of the copy is not controlled by ourselves, this string copy is prone to error. Memcpy (char DST, c* T char SRC, unsigned int len);

Copy len of memory from SRC to DST. This function has a controllable length. But there is the problem of memory overlay.

Sprintf is a formatting function. To format a piece of data into a string buffer in a specific format. The length of the sprintf formatting function is not controllable. It is possible that the formatted string will exceed the size of the buffer, causing an overflow.

14 The answer is:

a) int a; // An integer

b) int *a; // A pointer to an integer

c) int **a; // A pointer to a pointer to an integer

d) int a[10]; // An array of 10 integers

e) int *a[10]; // An array of 10 pointers to integers

f) int (*a)[10]; // A pointer to an array of 10 integers

g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer

h) int (a[10])(int); // An array of 10 pointers to functi that take an integer argument and return an integer

18. Functions of readwrite, readonly, assign, retain, Copy, nonatomic attributes

@property is a property access declaration that supports the following attributes:

Getter =getterName, setter=setterName, set setter and getter method names

Readwrite,readonly, set the level of available access

2. Assign and setter methods without performing any retain operations to solve the problem of primitive type and loop reference

Retain, setter methods release the old value and retain the new value, all implementations in this order (see CC for details)

Copy, setter method copy, same as retain process, old value release, copy new object, retainCount is 1. This is a mechanism introduced to reduce dependency on context. Copy is used when you don’t want a and B to share a piece of memory. A and B each have their own memory.

5, nonatomic access, no synchronization, multi-threaded concurrent access to improve performance. Note that without this attribute, both access methods are atomic transaction access by default. The lock is added to the instance level of the owning object. .

Atomic and nonatomic are used to determine whether getters and setters generated by the compiler are atomic operations. In a multithreaded environment, atomic manipulation is necessary, otherwise incorrect results may be caused.

19″NSMutableString *” represents the “NSMutableString” object itself, so there’s a difference.

NSString is just a pointer to an object.

Process oriented is to analyze the steps needed to solve the problem, and then use functions to implement these steps step by step, use when you can call one by one.

Object orientation is to decompose the transaction that constitutes the problem into various objects. The purpose of establishing objects is not to complete a step, but to describe the behavior of something in the whole step of solving the problem.