iOS Basic pen questions-Highlights II

Source: Internet
Author: User
Tags gcd file transfer protocol live chat

Objective

Reproduced below from: http://www.henishuo.com/objc-interview-two/

1, live chat app will not adopt the network transmission mode

A. UDP

B. TCP

C. HTTP

D. FTP

FTP: Is the file Transfer Protocol, is the short name of files Transfer protocol, it is used to control the two-way transmission of files on the Internet, so must not be instant chat use;

UDP: Is oriented to the non-connected Transport layer protocol, data transmission is unreliable, it just hair, regardless of receiving;

TCP: is a connection-oriented, reliable Transport layer protocol;

http: is a Hypertext Transfer protocol that corresponds to the application layer, and HTTP is TCP-based.

For a basic knowledge of socket theory, read the following article: Socket theory knowledge

Reference Answer: D

-----------------Cute Split-line------------------

2, the following technologies do not belong to multi-threaded is

Block A

B Nsthread

C nsoperation

D GCD

Apple offers three technologies such as Nsthread, Nsoperation, and GCD to handle multithreading.

For Nsthread, it is necessary to manage its life cycle;

For Nsopeartion is also one of the commonly used techniques, usually with nsoperationqueue together with the use;

For the GCD is usually seen most, the use is very convenient, and it with block to use, simple and concise.

Block is not a technology, but a code snippet, but has the ability to automatically capture contextual information, a bit like a function pointer, in fact, the global function is a special block.

About Nsoperation/nsoperationqueue, can read the author's article: multi-thread nsoperatoin/nsoperationqueue;

Reference Answer: A

-----------------Cute Split-line------------------

3, the difference between the thread and the process is not correct is

A process and threads are basic units that are run by programs provided by the operating system

There is a separate address space between the B threads

The main difference between C processes and threads is that they are different ways to manage operating system resources

D threads have their own stacks and local variables

This is the time to learn the knowledge of the operating system often test content, but often encountered in the work of multi-threading problems. Typically, a process represents an application, and the operating system provides threads to handle concurrency in order to make better use of resources. There is no separate address space between the threads, and the process is completed to return to the main thread, so that a thread dies is equal to the entire progress. Processes and threads are the basic unit of the operating system, but different division of labor, is two different ways of resource management. The resources required for a thread are derived from the process, which does not have its own independent resources, and it does not have its own stack and local variables.

FIX: Refer to the question that the answer and description do not meet.

Reference Answer: B

-----------------Cute Split-line------------------

4. The difference between heap and stack is correct

A for the stack, we need manual control, easy to produce memory leak

B for heaps, release work is automatically managed by the compiler without our manual control

C in Windows, the stack is the data structure to the high address extension, is a contiguous memory area, the top of the stack address and the maximum capacity of the stack is the system pre-defined

D for the heap, frequent new/delete is bound to cause memory space discontinuity, resulting in a large number of fragments, so that program efficiency is reduced

Stack is managed by the compiler, not our manual control, but the stack can allocate less memory, if you want to deal with big data, you need to allocate on the heap, so on the stack is more prone to memory Leak;

For the heap, we need to apply for our own memory, but also we need to manually release, otherwise it will cause memory leaks, for the heap, if too much memory space, will cause memory space is not connected, resulting in memory fragmentation, which makes the program less efficient.

Reference Answer: D

-----------------Cute Split-line------------------

5, the following callback mechanism is not correct to understand that

A target-action: When there is a close relationship between two objects, such as the view controller and a view below it.

B delegate: When an object receives multiple events and requires the same object to handle all events. The delegation mechanism must rely on a protocol-defined method to send a message.

C nsnotification: When multiple objects or two unrelated objects are required to handle the same event.

D Block: A simple task for a callback that only sends a single birth.

For the target-action mechanism, it is necessary to have a close connection between the two objects, such as between the controller and the cell, by setting the target as the Controller object, and the action being a callback method in the controller;

For the delegator mechanism, it is the standard callback mechanism provided by Apple, usually provides a standard protocol, followed by the proxy class to comply with the protocol, the most commonly used is to reverse the value, such as the turn on Bluetooth to feed back to the previous interface Bluetooth switch state;

For notifications, which is usually a many-to-many relationship, it does not care who is handling the message, any object can register for notification to the notification hub, and when the notification is sent, all objects that have registered the notification can receive the message. The most common scenario is cross-module, such as login module and other modules have a very close connection, but after successful login may need to do some processing, so often in the successful login or log out successfully sent a notification, so that each need to deal with the module to be processed correctly;

The block is fairly simple, and it only works on a one-off relationship, such as a callback after a successful or failed operation.

Reference Answer: B

-----------------Cute Split-line------------------

6, the understanding of Runloop is not correct

A each thread has its corresponding runloop

B Runloop of the default non-main thread is not running

C There is no need to enable runloop in a separate thread

D can add Nstimer to Runloop

Speaking of Runloop, it is a magic weapon of multithreading. Typically, a thread can only perform one task at a time, and it exits the thread when the task is finished. However, for the main thread is unable to exit, so we need to let the main thread immediate task completion, can also continue to wait to receive the event without exiting, then Runloop is the key to the magic. However, a non-main thread is usually meant to perform a task, and the resource is returned when executed, so the default is not to run Runloop.

Each thread has its corresponding runloop, but only by default the main thread of the Runloop is started, the other child threads Runloop default is not started, to start you need to start manually.

In a separate thread, you need to enable Runloop if you want to continue waiting for an event after you have finished processing a task without exiting.

Nsrunloop provides a way to add a nstimer, you can specify mode, if you want to make callbacks in any case, you need to set mode to common mode.

In essence, the Runloop default for child threads does not exist, because Apple uses lazy loading. If we do not call [Nsrunloop Currentrunloop] manually, we will not query whether there is a runloop of the current thread, and it will not be loaded, nor will it be created.

Here are some of the source code for Cfrunloop:

Should only being called by Foundation

T==0 is a synonym for "main thread" that's always works

Cf_export cfrunloopref _cfrunloopget0 (pthread_t t) {

if (pthread_equal (t, Knilpthreadt)) {

t = pthread_main_thread_np ();

}

__cfspinlock (&loopslock);

if (!__cfrunloops) {

__cfspinunlock (&loopslock);

Cfmutabledictionaryref dict = cfdictionarycreatemutable (kcfallocatorsystemdefault, 0, NULL, & Kcftypedictionaryvaluecallbacks);

Cfrunloopref Mainloop = __cfrunloopcreate (PTHREAD_MAIN_THREAD_NP ());

Cfdictionarysetvalue (Dict, Pthreadpointer (PTHREAD_MAIN_THREAD_NP ()), mainloop);

if (! Osatomiccompareandswapptrbarrier (NULL, Dict, (void * volatile *) &__cfrunloops)) {

Cfrelease (DICT);

}

Cfrelease (Mainloop);

__cfspinlock (&loopslock);

}

Cfrunloopref loop = (cfrunloopref) cfdictionarygetvalue (__cfrunloops, Pthreadpointer (t));

__cfspinunlock (&loopslock);

if (!loop) {

Cfrunloopref Newloop = __cfrunloopcreate (t);

__cfspinlock (&loopslock);

loop = (cfrunloopref) cfdictionarygetvalue (__cfrunloops, Pthreadpointer (t));

if (!loop) {

Cfdictionarysetvalue (__cfrunloops, Pthreadpointer (t), newloop);

loop = Newloop;

}

Don ' t release run loops inside the Loopslock, because cfrunloopdeallocate may end up taking it

__cfspinunlock (&loopslock);

Cfrelease (Newloop);

}

if (pthread_equal (T, Pthread_self ())) {

_CFSETTSD (__cftsdkeyrunloop, (void *) loop, NULL);

if (0 = = _CFGETTSD (__cftsdkeyrunloopcntr)) {

_CFSETTSD (__CFTSDKEYRUNLOOPCNTR, (void *) (pthread_destructor_iterations-1), (Void (*) (void *)) __cffinalizerunloop);

}

}

return loop;

The key loading process is as follows:

Check the global dictionary for the existence of the thread's runloop and exit if there is, otherwise

Create a new runloop into the global dictionary

Reference Answer: C

-----------------Cute Split-line------------------

7, the breakpoint continues to need to add in the request header control to continue the most important keywords

A Range

B length

C type

D size

Reason: For the implementation of the file's breakpoint continuation and breakpoint download, you need to set the Range entity header in the request header, specify the position of the first byte and the position of the last byte, and the corresponding response header has a content-range, indicating the length of the whole entity and part of the insertion position, such as Content-range:bytes 0-500/801, specifies the range for the current range with the total file size.

Reference Answer: A

-----------------Cute Split-line------------------

8, the MVC advantage is not correct is

A Low Coupling

B High reusability and applicability

C lower life-cycle costs

D Code Efficiency

Reason: MVC is only an architectural design pattern, it has a relatively long history of appearance. Model-controller-view is the most common architecture design pattern in the development, by connecting model, View, Controller, model as data processing plant, Controller as bridge, processing business, View is only a data presentation layer and should not be business-agnostic. The MVC design pattern reduces the coupling, provides reusability and applicability, and can effectively improve the development efficiency.

Reference Answer: D

-----------------Cute Split-line------------------

9, mixed OBJC and C + + source files need to change the file format suffix

A. C

B. cpp

C. mm

D. M

Reason: ObjC to be mixed with C + + source code files, you will need to change the file suffix to. mm. There is nothing to dwell on, remember!

Reference Answer: C

-----------------Cute Split-line------------------

10, OBJC declare a class to use the compilation instructions are

A @interface SomeClass

B @protocol SomeClass

C @implementation SomeClass

D @autorelease SomeClass

Reason: A is an instruction to declare a class, B is an instruction to declare an agreement, C is an instruction to implement the definition of a class, and D is an instruction that declares an automatic release of a pool.

Reference Answer: A

-----------------Cute Split-line------------------

11, MRC file in the ARC Project mixed compilation, need to be in the file compiler flags to add what parameters

A-shared

B-fno-objc-arc

C-fobjc-arc

D-dynamic

Reason: For Arc engineering, if you want to mash MRC files, you need to add-FNO-BOJC-ARC to the project's compiler flags; for MRC projects, if you want to have an arc file mixed, you need to set it to-fobjc-arc.

Reference Answer: B

-----------------Cute Split-line------------------

12, the following about OBJECTIVE-C memory management description of the error is

A when using arc to manage memory, there is no autorelease in the code

B Autoreleasepool will release the objects allocated in the drain.

C when using arc to manage memory, large allocations of objects in the thread without autoreleasepool can cause memory leaks

D cannot use Nszone in projects that use arc

Reason: Arc is just most of the time compiling the code that automatically adds memory management to us, but it's only invisible to our source code, but at compile time, the compiler adds the relevant memory management code. For an auto-free pool, the reference count of all objects in the auto-free pool is reduced by one at drain, and its memory is automatically freed if the reference count is 0. If we need to allocate a lot of memory in the thread, we should add an auto-free pool to prevent memory leaks. For example, to allocate a large amount of memory processing data in a for loop, we should add an auto-free pool within the For loop, freeing the memory after each loop to prevent memory leaks. In an arc project, it is natural that you cannot use Nszone manually or call the Dealloc of the parent class.

Reference Answer: A

-----------------Cute Split-line------------------

13. Which of the following does not belong to the object data serialization method

A JSON

B Property List

C XML

D HTTP

Reason: Data serialization is the data of the object into a certain format, the most commonly used in iOS development is JSON, some companies use XML, I have never encountered the use of property list to transfer data, but we will be some small amount of data stored in the property The list, such as Nsuserdefaults, is the operation of the plist file. HTTP is a hyper-file transfer Protocol, but a protocol.

Reference Answer: D

-----------------Cute Split-line------------------

14, in the Uikit, the difference between frame and bounds is

A. Frame is an alias of bounds

B. Frame is the inheriting class of bounds

C. Frame reference System is the parent view coordinate, bounds's reference system is its own coordinates

D. Frame reference System is its own coordinate, bounds's reference system is the coordinates of the parent view

Reason: Frame's reference system is the coordinate system of the parent view, and bounds is the coordinate system of the reference self. Modify the bounds of the parent view to move the child view. However, this is usually not the case, if the parent view does not need to move, there is no need to modify the bounds, directly modify the sub-view frame can be implemented.

Reference Answer: C

-----------------Cute Split-line------------------

15, the following about the thread management error is

A. The cost of GCD is greater than that of nsthread.

B. You can modify UI elements in a child thread

C. Nsoperationqueue is a higher-level package than Nsthread

D. GCD can assign threads based on different priority levels

Reason: First, the UI element's update must be in the main thread. GCD is used in conjunction with block, the block needs to automatically capture the context variable information and so on, so it needs more resources, so it is more expensive than nsthread. Nsoperationqueue with Nsoperation, it is easier to manipulate threads than Nsthread. GCD provides multiple priorities, and we can assign threads to us automatically based on the priority we set.

Relationship Nsoperationqueue, please read the article: Nsoperationqueue

Reference Answer: B

-----------------Cute Split-line------------------

At last

The article inevitably has to say unreasonable place, if you think the statement is incorrect or where there is the wrong place, please leave a comment in the comments, the author will be in the first time to amend!!!

iOS Basic pen questions-Highlights II

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.