22. iOS face test and self-organizing · Four

Source: Internet
Author: User
Tags gcd shallow copy

1. Why do agents use weak? What is the difference between an agent's delegate and datasource? What is the difference between block and agent?

A: To avoid circular references. Weak indicates that the object is not responsible for keeping the object delegate, delegate the object's destruction is externally controlled. Strong the object strongly references delegate, the outside world cannot destroy delegate objects, which can cause circular references. DataSource is about the content of the view, including properties, data, and so on, while delegate is a method that we can call, all operations. Blocks and proxies can solve the problem of inter-object interaction, block is lighter, simpler, has direct access to the context, the code is usually in the same place, so the reading code is consistent. The disadvantage is that it can easily cause circular references. Delegate more heavy, need to implement the interface, its methods separate, many times need to store some temporary data, and the related code needs to be separated into a good read everywhere, the advantage is that it is decorated with the weak keyword, will not cause circular references.

2. What is the nature of the attribute? Which parts are included? What are the default keywords for a property? What are @dynamic keywords and @synthesize keywords for?

A: The nature of the property is @property = Ivar+getter+setter, which means that the @property system automatically generates getter and setter methods. The default keywords for properties include atomic,nonatomic, @synthesize, @dynamic, Getter=gettername,setter=settername,readwrite,readonly,assign, Retain,copy.
@dynamic: The property accessor method that represents the variable, is implemented dynamically, and you need to inherit from the NSObject (BOOL) Resolveinstancemethod: (SEL) The method or function that specifies the dynamic implementation in the SEL method.
@synthesize: If no setter and getter are implemented, the compiler can automatically implement getter and setter methods.

3.NSString Why use the Copy keyword, if you use strong what will be the problem? (Note: There is no saying that using strong is a must.) The use of copy and strong is determined by the situation)

A: For when the nsmutablestring assigned to NSString, it will be different, with copy words NSString value will not change, with the strong will change, with the value of nsmutablestring change. If the assignment is a NSString object, then using copy or strong, the result is the same, because the NSString object cannot change its value at all, he is immutable.

4. How do I make copies of the objects I write?

A: You need to implement the Nscopying protocol if you want to write objects that have copy functionality. If the custom object is divided into both variable and non-variable versions, then both the nscopying and nsmutablecopying protocols will be implemented, but it is generally not necessary to implement the Nscopying protocol.

5. What is the difference between copy and mutablecopy of a mutable and immutable collection class? If a collection is a content copy, is the element in the collection also a copy of the content?

A: For non-mutable objects, copy operation is shallow copy, mutablecopy is deep copy. For non-mutable objects, mutablecopy is not only a deep copy, but also the type of variable object that is returned by the object type or immutable object type. Content replication is a deep copy, the collection of deep copy has two methods, you can use Initwitharray:copyitems: The second parameter is set to Yes for deep copy, such as: nsdictionary shallowcopydict = [ Nsdictionary alloc]initwithdictionary:somedictionary Copyitems:yes]; If you use this method to copy deeply, each element in the collection will receive a copywithzone: message. If the objects in the collection follow the Nscopying protocol, the object is deeply copied to the new collection. If an object does not follow the Nscopying protocol, an attempt to make a deep copy in this way will cause an error. Copywithzone: This copy can only provide a single layer of memory, rather than a true deep copy. The second method is to archive the collection, such as: Nsarray truedeepcopyarray = [Nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver Archiveddatawithrootobject:oldarray]];

6. Why does the Iboutlet modified UIView also apply to weak keywords?

A: Since there is an outside chain then the view must exist in Xib or storyboard, and the view already has a strong reference to it.

7. What is the difference between nonatomic and atomic? is atomic absolutely thread-safe? Why? If not, how should that be done?

The difference between a:nonatomic and atomic is that they automatically generate getter and setter methods differently, if you write getter and setter methods yourself, then (Getter,setter,retain,copy, Assign) only play a hint, write not write all the same.
For atomic properties, the system-generated getter and setter guarantees the operational integrity of the get,set and is not affected by other threads. For example, thread A's getter method runs to half, thread B calls the setter, then thread A's getter can still get a complete object.
And nonatomic there is no guarantee, so the speed is faster than the atomic.
However, atomic can not guarantee thread safety, if thread A calls the getter, while thread B and thread C both tune the setter, the last thread aget to the value, three possible: the original value before the B,c set, it may be the value of B set, it may be C The value of the set. At the same time, this final value may be either the value of the B set or the value of the C set. To be secure, you can use the thread lock.

How is 8.UICollectionView custom layout implemented?

A:uicollectionviewlayoutattributes,uicollectionviewflowlayout.

9. What are the drawbacks of developing the interface with storyboard? How to avoid it?

A: Difficult to maintain, if you need to change the global font, if the code is very good to do, PCH or header file changes in the good. If it's a storyboard, it's a hassle to have one change.
If there are too many scenes in the storyboard, opening the storyboard will be slow.
Error location is difficult, many error hints ambiguous.

10. What is the difference between a process and a thread? What is the difference between synchronous and asynchronous? What is the difference between parallelism and concurrency?

A: The process is an in-memory running application, such as in a Windows system, a running EXE is a process.
A thread is an execution process in a process.
The synchronization is executed sequentially, executing one after the next. Need to wait, coordinate to run.
Async is independent of each other, waiting for an event to continue to do their own things, do not need to wait for these events to work after the completion.
Parallel and concurrency is the equivalent of three people eat a steamed bread at the same time, the latter equivalent to a person at the same time eat three steamed bread.
Concurrency (Concurrence): refers to two or more than two events or activities that occur within the same time interval. The essence of concurrency is that a physical CPU (or multiple physical CPUs) can be multiplexed between several programs, and concurrency is forcing multi-user sharing for limited physical resources to improve efficiency.
Parallelism (parallelism) refers to the occurrence of two or more two or more events or activities at the same time. In a multi-channel program environment, parallelism enables multiple programs to execute simultaneously on different CPUs at the same time.
Difference: (concurrency) A single processor handles multiple tasks simultaneously and (in parallel) multiple processors or multi-core processors simultaneously processing several different tasks.

11. Inter-thread communication?

A:nsthread, GCD, Nsoperation.

Some of the common functions of 12.GCD? (Group,barrier, Semaphore, thread synchronization)

A:1. Deferred execution of task functions: Dispatch_after (...).
2. Execute dispatch_once (...) at once.
3. Fence function Dispatch_barrier_async/dispatch_barrier_sync.
4. Use dispatch_group_t for queue groups.
5.GCD timer.

13. How do I use queues to avoid resource looting?

The A:dispatch_barrior_async function is in the parallel queue, waiting for the first two operations to be done in parallel.

14. Several scenarios for data persistence (Fmdb used)

A:coredata,realm,fmdb.

15. Say a few ways to Appdelegate? What methods are called from the background to the foreground? What methods were invoked the first time it was started? What methods are called from the foreground to the background?

A:
1. When the program runs for the first time and is about to display the window, the actions we complete in this method

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. When the program enters the background, the first execution program will cancel the active method

(void)applicationWillResignActive:(UIApplication *)application

3. This method is called when the application enters the background

(void)applicationDidEnterBackground:(UIApplication *)application

4. Call when the program enters the foreground

(void)applicationWillEnterForeground:(UIApplication *)application

5. The application has become active (application running state)

 - (void)applicationDidBecomeActive:(UIApplication *)application

6. Called when the program is about to exit, if the application supports background running, the method is Applicationdidenterbackground: replace

(void)applicationWillTerminate:(UIApplication *)application
What are the 16.NSCache better than nsdictionary?

A:nscache is a container class, similar to Nsdictionary, that stores and queries values in key-value form for temporary storage of objects.
Note that the difference between it and nsdictionary is that the key in the Nscache does not have to implement the key in the copy,nsdictionary to implement copy.
The objects stored in Nscache do not have to implement the Nscoding protocol, because after all, temporary storage, similar to the memory cache, is released after the program exits.

17. Do you know designated Initializer (specify initialization function)? What do you need to be aware of when using it?

A: for example:

- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil NS_DESIGNATED_INITIALIZER;- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
18. What effect does the description method achieve?

A:1.nslog (@ "%@", Objecta), which automatically calls Objecta's description method to output objecta description information.
The 2.description method returns the descriptive information for the object by default (the default implementation is to return the class name and the memory address of the object)
The 3.description method is a method of the base class NSObject, because its default implementation is to return the class name and the memory address of the object, so that using NSLog to output the OC object is not very significant because we do not care about the memory address of the object. What is more concerned is the value of some variables inside the object. Therefore, the description method is often overridden to override the default implementation of the description method.

What mechanism does 19.OBJC use to manage object memory?

A: Determine whether an object needs to be released by Retaincount mechanism. Each time Runloop, will check the object's Retaincount, if the Retaincount is 0, indicating that the object has no place to continue to use, can be released.

What is the essence of 20.block? How many blocks are there? What are the situations that are generated?

The A:block object is a struct with the ISA pointer pointing to its own class (the global malloc stack) with the Desc struct describing the block's information,forwarding pointing to itself or the heap on its own address, if the block object intercepts the variable , these variables also appear in the block structure. The most important block struct has a function pointer, which points to block code blocks. The parameters of a block struct's constructor, including the function pointer, describe the structure of the block, automatically intercept the variable (global variable is not intercepted), and refer to the block variable. (block objects are also transformed into structs)
Block blocks generate a function at compile time, and the first parameter of the function is the block object struct pointer mentioned earlier. Executing block is equivalent to executing
the function pointer inside the block inside the forwarding.

22. iOS face test and self-organizing · Four

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.