IOS Interview Basic Questions

Source: Internet
Author: User
Tags variable scope uikit

1.UIWindow and UIView and Calayer's contact and difference?

A: UIView is the base class for the view, Uiviewcontroller is the base class for the view controller, and Uiresponder is an object that can respond to touch events on the screen;

UIWindow is a subclass of UIView, the main role of UIWindow: one is to provide a region to show UIView, and the other is to distribute the event to UIView, an application basically only one uiwindow.

All things in the root, UIView and Calayer are all old fathers are nsobjet. Visible Uiresponder is used to respond to events, that is, UIView can respond to user events.

The difference between Calayer and UIView:

The inheritance structure of 1.1 UIView is: Uiresponder:nsobject.

The inheritance structure of Calayer is: NSObject. Visible Uiresponder is used to respond to events, that is, UIView can respond to user events, Calayer inherit directly from NSObject because the Uiresponder class is missing and cannot respond to any user events

1.2 belongs to the framework, UIView is defined in the/system/library/frameworks/uikit.framework, UIKit is mainly used to build the user interface, and can respond to events. Calayer is defined in the/system/library/frameworks/quartzcore.framework. and Calayer as a low-level, underlying object that can host the drawing content appears in the frame.

1.3 UIView The biggest difference compared to Calayer is that UIView can respond to user events, and Calayer is not. UIView focuses on the management of display content, and Calayer focuses on drawing content. UIView is a high-level package based on Calayer.

1.4 Similar support 1: Similar tree structure 2: Display content Rendering Method 3: Layout constraints

To summarize: UIView is used to display content and can handle user events. Calayer is used to draw content, to animate content dependent on and UIView to display, not to handle user events

Why are there two sets of systems that are not two systems? UIView and Calayer are interdependent relationships. UIView relies on content provided with Calayer, Calayer relies on the container provided by Uivew to display the content being drawn. In the final analysis Calayer is the basis of all this, if no calayer,uiview itself will not exist, UIView is a special calayer implementation, adding the ability to respond to events. UIView itself, more like a Calayer manager, accesses its properties related to drawing and coordinates, such as frame,bounds, and so on, essentially accessing the relevant properties of the Calayer it contains.

The UIView layer tree is inside the system and is maintained by the system with three copies (this understanding is a bit doubt).

The first, logical tree, is what you can manipulate in the code, such as changing the properties of a layer and so on.

Second, the animation tree, which is an intermediate layer, the system is changing the properties on this level for various rendering operations.

Third, show tree, the content of this tree is currently being displayed on the screen.

The logical structure of the three trees is the same, the difference is only the individual attributes.

Outside of the main layer of the UIView, changes are made to its sublayer, the properties of the child layer, and the system is automatically animated.

Calayer coordinate system and uiview a bit different, it has a property called Anchorpoint, it uses the cgpoint structure, but the range is 0~1, that is, set according to the scale. This point is the coordinate origin of the various graphic transformations and changes the position of the layer's position, whose default value is {0.5, 0.5}, which is the center of the layer.

Haha, this is enough to say a pot of the put, although the feeling is actually no egg use, but remember must say the vivid.

The reference links are as follows:

    • http://o0o0o0o.iteye.com/blog/1728599
    • Http://www.cnblogs.com/pengyingh/articles/2381673.html

2. What are the common fields in the property?

Strong,weak,retain,assign,copy Nomatic,readonly,

3. The difference between strong,weak,retain,assign,copy nomatic and so on.

Assign: Simple assignment, do not change the index count (Reference counting) to the underlying data class

Copy: Create an object with an index count of 1 and then release the old object. To NSString

Retain: Frees the old object, assigns the value of the old object to the input object, and then increases the input object's index count to 1 for the other nsobject and its subclasses

The difference between weak and strong: weak and strong are different when an object no longer has a strong-type pointer to it, it is released even if there is a weak-pointer pointing to it. Once the last strong pointer is left, the object will be released and all remaining weak pointers will be cleared.

Copy and retain:

Copy actually creates an identical object, and retain is not.

Copy is a copy of the content, and retain is a pointer copy.

Copy is a copy of the content, for like NSString, it is true, if the copy is Nsarray then just copy the pointer to the corresponding element in the array. This is called "shallow copy".

Atomic is a thread-protection technique used by OBJC, basically to prevent the data from being read by another thread when the write is not completed. This mechanism is resource-intensive, so nonatomic is a very good choice on small devices such as the iphone, if there is no communication programming between multiple threads.

For nsstring Why use copy reference this link

    • http://southpeak.github.io/blog/2015/05/10/ioszhi-shi-xiao-ji-di-%5B%3F%5D-qi-2015-dot-05-dot-10/

Differences between the 4.__block and __weak modifiers:

__block can be used in either ARC or MRC mode, can be decorated with objects, and can also be decorated with basic data types.

__weak can only be used in Arc mode, can only be decorated with objects (nsstring), and cannot be decorated with basic data types (int).

The __block object can be re-assigned in the block, __weak not.

5. What are the common Http status codes?

HTTP Status: 302 is request redirection. More than 500 is a server error. More than 400 is a request link error or the server could not be found. More than 200 is correct. 100 above is the request accepted successfully.

2-3 problem Reference link http://zhangmingwei.iteye.com/blog/1748431

6. The wording of the singleton. What should you pay attention to when using arrays in a single case?

1

2

3

4

5

6

7

8

9

Static Pgsingleton *sharedsingleton;

+ (Instancetype) Sharedsingleton

{

static dispatch_once_t Oncetoken;

dispatch_once (&oncetoken, ^{

Sharedsingleton = [[Pgsingleton alloc] init];

});

return Sharedsingleton;

}

In fact, the above is not a standard single-case method, the standard single-case method needs to rewrite Copywithzone,allocwithzone,init, to ensure that the object created in any way only one, here is not detailed.

When using Nsmutablearray, it is necessary to add an atomic attribute to prevent multiple places from traversing and modifying it at the same time. And the property uses strong, and writes a method of traversal and modification. Plus lock. Lock,unlock. (PS: Consider performance issues as much as possible to avoid the use of locks, in the Apple document Zhang see do not ask me why, I also forgot to check my own. )

Reference to a singleton, and not to misuse a single case reference

    • http://www.jianshu.com/p/7486ebfcd93b
    • http://blog.codingcoder.com/singletons/

The role of 7.static keywords

1. The function body static variable scope is the function body, differs from the auto variable, the memory of the variable is allocated only once,

Therefore, its value remains the last value at the next call;

2. Static global variables within the module can be accessed by functions used within the module, but not by other functions outside the module;

3. The static function within the module can only be called by other functions within the module, and the use of the function is limited to the module in which it is declared;

4. Static member variables in a class are owned by the entire class and have only one copy of all objects of the class;

5. Static member functions in a class are owned by the entire class, which does not receive the this pointer, and therefore can only access static member variables of the class.

Delivery of events in 8.iOS: Response chain

Briefly say:

The event is passed along a specified path until it encounters an object that can handle it. First, a UIApplication object gets an event from the top of the queue and distributes (dispatches) it for processing. Typically, it passes events to the application's key window object, which passes events to an initial object for processing. The initial object depends on the type of event.

Touch events. For touch events, the Window object first attempts to pass the event to the view where the touch occurred. That view is called the Hit-test (click Test) view. The process of finding the hit-test view is called hit-testing, see hit-testing Returns the View Where a Touch occurred. "

Motion and remote control events. For these events, the Window object passes the shaking-motion (shaking motion) or the remote control event to the first responder to handle. First responder See "The Responder Chain is made up of Responder Objects."

IOS uses hit-testing to find the view that the event occurred. Hit-testing includes checking whether a touch event occurs within the scope of any related view object, and, if so, recursively checks the child view of all views. At the bottom of the view level, if it contains a touch point, it is the hit-test view. When iOS determines the Hit-test view, it passes the touch event to the view for processing.

Reference link:http://yishuiliunian.gitbooks.io/implementate-tableview-to-understand-ios/content/uikit/132event-chains.html

9. Heap and Stack differences

Management mode: For the stack, is automatically managed by the compiler, without our manual control, for the heap, the release of work by the programmer control, easy to produce memory leak.

Application Size:

Stack: Under Windows, the stack is the data structure to the low address extension, which is a contiguous area of memory. This sentence means that the top of the stack of the address and the maximum capacity of the stack is the system pre-defined, in Windows, the size of the stack is 2M (also said 1M, in short, is a compile-time determination of the constant), if the request for more space than the stack's remaining space, will prompt overflow. Therefore, the space available from the stack is small.

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 is stored with a linked list of free memory address, is naturally discontinuous, and the chain of the list of traversal direction is from the low address to high address. The size of the heap is limited by the valid virtual memory in the computer system. Thus, the space of the heap is more flexible and relatively large.

Fragmentation problem: 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. For the stack, there is no problem, because the stack is advanced out of the queue, they are so one by one correspondence, so that there will never be a memory block from the middle of the stack popped

Allocation method: The heap is dynamically allocated and there are no statically allocated heaps. Stacks are allocated in 2 ways: static allocation and dynamic allocation. Static allocations are done by the compiler, such as the allocation of local variables. The dynamic allocation is assigned by the ALLOCA function, but the dynamic allocation of the stack is different from the heap, and his dynamic allocation is released by the compiler without our manual implementation.

Allocation efficiency: The stack is the data structure provided by the machine system, the computer will support the stack at the bottom: allocate the address of the special register storage stack, the stack stack has a special instruction execution, which determines the efficiency of the stack is high. The heap is provided by the C + + function library, and its mechanism is very complex.

IOS Interview Basic Questions

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.