iOS face question (iv)

Source: Internet
Author: User

1. What are the options for background refresh and VoIP and music playback and positioning?

Uibackgroundtaskidentifier

2. Why do you use GCD instead of nsoperation in your project? Have you ever found out that the foreign Daniel is using nsoperation for their multithreading? Can you tell me the reason why they did it?

Relationship: ①: First understand the relationship between the two, nsopertaionqueue with GCD build encapsulated, is gcd high-level abstraction!
②:GCD only supports FIFO queues, while queues in Nsoperationqueue can be prioritized to perform order adjustments for different operations. GCD does not support dependency settings between asynchronous operations. If an operation relies on data from another operation (the producer-consumer model is one of them), use Nsoperationqueue to perform the operation in the correct order. GCD does not have built-in dependency support.
③:nsoperationqueue supports KVO, which means that we can observe the execution state of a task.
To understand the above differences, we can answer from the following angles
Performance: ①:GCD is closer to the bottom, while Nsoperationqueue is more advanced abstraction, so GCD is the fastest in the pursuit of performance at the bottom of the operation. This depends on using instruments for code performance analysis, if necessary
②: Transactional, sequential line, dependency between asynchronous operations. GCD needs to write more code to implement it, and Nsoperationqueue has built in these support
③: Nsoperationqueue is a better choice if the process of an asynchronous operation requires more interaction and UI rendering. In the underlying code, the tasks are less dependent on each other and require higher concurrency, and the GCD is more advantageous

3, what is KVC and kvo?

KVC (key-value-coding) Internal implementation: an object in the call SetValue, (1) first to find the method name according to the operation of the required environment parameters. (2) He will combine the environment parameters from his own Isa pointer to find the specific method implemented by the interface. (3) The specific method can be directly found. KVO (key-value-observing): When the observer registers the attributes of an object, the ISA pointer points to an intermediate class instead of the real class when the object's ISA pointer is modified. So the ISA pointer does not actually need to point to the real class of the instance object. So our program is best not to rely on the ISA pointer. When invoking a method of a class, it is best to clarify the class name of the object instance

4, how to make their own class with the copy modifier? How do I rewrite the setter with the Copy keyword?

The Nscopying protocol is required if you want the object you write to have a copy function. If a custom object is divided into a mutable version and an immutable version, then both the nscopying and nsmutablecopying protocols are implemented.
Specific steps:
1. It is necessary to declare that the class complies with the Nscopying protocol
2. How to implement the Nscopying protocol.
The protocol has only one method:
-(ID) Copywithzone: (Nszone *) zone;
Note: With the copy modifier, the copy method is called, but what really needs to be implemented is the "Copywithzone" method.

5. What is the role of @synthesize and @dynamic respectively?

@property have two corresponding words, one is @synthesize (synthetic instance variable), and the other is @dynamic.
If @synthesize and @dynamic are not written, then the default is @synthesize var = _var;
In the implementation code of the class, you can specify the name of the instance variable by @synthesize syntax. (@synthesize var = _newvar;)

  1. The semantics of @synthesize is that if you do not implement setter methods and Getter methods manually, then the compiler will automatically add these two methods to you.
  2. @dynamic tells the compiler that the setter and getter methods of the property are implemented by the user themselves and are not generated automatically (e.g., @dynamic var).
6, how to synchronize several asynchronous calls with GCD? (such as loading multiple pictures asynchronously based on several URLs, and then compositing an entire image after the download is complete)
// 使用Dispatch Group追加block到Global Group Queue,这些block如果全部执行完毕,就会执行Main Dispatch Queue中的结束处理的block。// 创建队列组dispatch_group_t group = dispatch_group_create();// 获取全局并发队列dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_group_async(group, queue, ^{ /*加载图片1 */ });dispatch_group_async(group, queue, ^{ /*加载图片2 */ });dispatch_group_async(group, queue, ^{ /*加载图片3 */ }); // 当并发队列组中的任务执行完毕后才会执行这里的代码dispatch_group_notify(group, dispatch_get_main_queue(), ^{        // 合并图片});
7. What is the function of Dispatch_barrier_async (fence function)?
函数定义:dispatch_barrier_async(dispatch_queue_t queue, dispatch_block_t block);作用:    1.在它前面的任务执行结束后它才执行,它后面的任务要等它执行完成后才会开始执行。    2.避免数据竞争// 1.创建并发队列dispatch_queue_t queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_CONCURRENT);// 2.向队列中添加任务dispatch_async(queue, ^{  // 1.2是并行的    NSLog(@"任务1, %@",[NSThread currentThread]);});dispatch_async(queue, ^{    NSLog(@"任务2, %@",[NSThread currentThread]);});dispatch_barrier_async(queue, ^{    NSLog(@"任务 barrier, %@", [NSThread currentThread]);});dispatch_async(queue, ^{   // 这两个是同时执行的    NSLog(@"任务3, %@",[NSThread currentThread]);});dispatch_async(queue, ^{    NSLog(@"任务4, %@",[NSThread currentThread]);});// 输出结果: 任务1 任务2 ——》 任务 barrier ——》任务3 任务4 // 其中的任务1与任务2,任务3与任务4 由于是并行处理先后顺序不定。
8. What is Runloop

Literally, it is the cycle of running, which is internally a do-while loop that constantly handles various tasks within the loop.
One thread corresponds to a runloop, and the basic function is to keep the program running and handle various events in the app. Through Runloop, something runs, nothing on the rest, you can save CPU resources, improve program performance.

The run loop of the main thread is started by default. iOS app, the program starts with a main () function like this
int main (int argc, char * argv[]) {
@autoreleasepool {
Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]));
}
}

9, runtime implementation of the mechanism is what, how to use, generally used to do?

1). header files that need to be imported when using <objc/message.h> <objc/runtime.h>
2). Runtime runtime mechanism, which is a set of C language libraries.
3). In fact, all of the OC code that we write is eventually turned into the runtime library.
Like what:
The > class turns into a data type such as a struct in the runtime library,
Method into the C language function in the runtime library,
Peacetime tuning method is turned into the Objc_msgsend function (so that OC has a message sending mechanism)
OC is a dynamic language, and each method is dynamically transferred to the message at run time, namely: Objc_msgsend (receiver, selector).
[Stu Show]; When OBJC is dynamically compiled, it is referred to as: Objc_msgsend (Stu, @selector (show));
4). Therefore, it can be said that the Runtime is the lower level of OC implementation, is OC behind the actors.
What can I do with the runtime library?
The runtime library contains APIs related to classes, member variables, and methods.
Like what:
(1) Gets all the member variables inside the class.
(2) Dynamically add member variables for the class.
(3) The method of dynamically changing class is implemented.
(4) Adding new methods to the class dynamically, etc.
So, with the runtime, how to change how to change.

10. What is TCP/UDP?

TCP: Transmission Control Protocol.
UDP: User Data Protocol.

TCP is connection-oriented, and establishing a connection requires a three-time handshake, which is a reliable transport layer protocol.
UDP is non-connected, data transmission is unreliable, it just hair, regardless of receiving.
Simply put, TCP focuses on data security, while UDP data transfer is fast, but security is common.

The answer is to collect, if there is anything wrong, please correct me!

iOS face question (iv)

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.