[Interview] interview questions for iOS development (III)

Source: Internet
Author: User
Tags notification center

[Interview] interview questions for iOS development (III)
1. What are iOS data persistence storage solutions?

Reference answer:

Plist attribute list storage (such as NSUserDefaults) file storage (such as writing binary data to file storage, using NSFileManager to write the downloaded binary data to a file for storage) NSKeydeArchiver archive storage, it is commonly used for automated archiving/archiving, and you want to learn how to implement automated archiving/archiving through runtime, which can be stored in the database SQLite3 (such as FMDB and Core Data) 2. What is the directory structure of the sandbox? In what scenarios are they generally used?

Reference answer:

Application: stores the program source file. The file is digitally signed before mounting. After mounting, you cannot modify the Documents: What should be saved? The persistent data generated during running. This log is backed up when the iTunes synchronization device is used. For example, a game application can save the game archive in the directory tmp: Save the response? The temporary data required during running, so that? After that, delete the corresponding files from the directory. When the application is not running, the system may also clear files in the directory. The Library/Caches directory is not backed up when the iTunes synchronization device is running? This directory is not backed up when iTunes synchronizes devices .? Generally, the storage volume is large and non-important data does not need to be backed up. For example, if the network data is cached and stored in the Library/Preference under Caches, all Preference Settings of the application should be saved, such as setting for iOS? Will query the response in this directory? . What is the difference between the macro defined by define and the constant defined by const?

Reference answer:

# Define defines macro commands. In the preprocessing phase, the program only replaces the content defined by # define. Therefore, when the program is running, the constant table does not use the macro defined by # define. The system does not allocate memory for it and does not check the data type during compilation. The error probability is higher. The constant defined by const is stored in the constant table during program running. The system allocates memory for it and checks the type during compilation. # Pay attention to the "Edge Effect" when defining the expression in define, for example, the following definition:

 

 
1 2 3 4 # Define N 2 + 3 // The expected N value is 5, so we use N int a = N/2; // The expected a value is 2.5, the actual value of a is 3.5.
4. What are common scenarios for memory loop reference?

Reference answer:

Timer (nstmer): nstmer is often used as a member variable of a class, while NSTimer must specify self as the target during initialization, which easily leads to loop reference (self-> timer-> self ). In addition, if timer is always in the validate status, its reference count will always be greater than 0. Therefore, after the timer is no longer used, you should first call the invalidate method block: during block copy, objects used inside the block are strongly referenced (ARC) or retainCount is increased by 1 (non-ARC ). Improper use of blocks in the ARC and non-ARC environments will cause circular reference problems. Generally, a class uses blocks as its own attribute variables, then the class uses the class itself in the block method body. In short, it is self. someBlock = Type var {[self dosomething]; or self. otherVar = XXX; or _ otherVar = ...}; The reason for the loop is: self-> block-> self or self-> block-> _ ivar (member variable) proxy (delegate ): the issue of circular references on delegation has become a common topic. The killer to avoid this issue is also simple to crying. The word is: Use assign (MRC) or weak (ARC) to declare delegate ), never try retain or strong. After all, this basically cannot escape loop reference! 5. Does weak self in the block need to be added at any time?

Reference answer:

It is not always good to add at any time. Loop reference occurs only when there is a structure chain such as self-> block-> self. property/self-> _ ivar. After a good analysis, we can infer whether there is a circular reference problem.

6. Must the code executed in the queue and main queue of GCD be in the main thread?

Reference answer:

The Code executed in the queue is not necessarily in the main thread. If the queue is created in the main thread, the executed code is executed in the main thread. If it is created in a child thread, it will not be executed in main thread. The main queue is in the main thread, so it will be executed in the main thread. You can obtain the main queue. You do not need to create it. You can obtain it by calling the dispatchgetmain_queue method. 7. Can I directly access the member variables declared in the header file (not attributes) from the outside?

Reference answer:

External access to the member variables declared by the header file is not allowed. You need to provide the getter method of the member variables to access the object externally. The property has already automatically generated the getter Method for us, so we can directly access the property externally.

8. What is the difference between TCP and UDP?

Reference answer:

TCP: connection-oriented, reliable transmission (ensuring data correctness and data transmission in sequence), used to transmit a large amount of data (stream mode), slow speed, and costly connection establishment (time, system Resources ). UDP: for non-connection, unreliable transmission, for transmitting a small amount of data (packet mode), fast, and packet transmission. 9. What are the differences between MD5 and Base64? What are their respective application scenarios?

Reference answer:

MD5 and Base64 are almost used for encryption-related functions. They are the most commonly used in actual development.

MD5: it is an irreversible Digest algorithm used to generate a digest and cannot be cracked to obtain the original text. Generally, a 32-bit digest is generated to verify the validity of the data. For example, in the network request interface, the client and the server use the same rule to generate a summary by generating all the parameters to prevent tampering. For example, when downloading an object, a summary of the object is generated to verify whether the object is damaged. Base64: it is an encryption algorithm that is reversible. After encode is used, you can decode it to obtain the original text. During development, some companies use base64 to convert images and then upload them. When performing encryption-related functions, data is usually encrypted/decrypted using base64. 10. How can I implement this by sending 10 network requests and then receiving all the responses and then performing subsequent operations?

Reference answer:

According to the question analysis, a function is executed only after all 10 requests are completed. For example, to merge a large image after downloading 10 images, You Need To asynchronously download all the images before merging them into a large image.

Practice: Use dispatch_group_t to add each request to the Group, and put the operations merged into a large graph in dispatch_group_notify.

 
1 2 3 4 5 6 7 8 9 10 Incluqueue = queue (queue, 0); dispatch_group_t group = dispatch_group_create (); dispatch_group_async (group, queue, ^ {/* attach image 1 */}); dispatch_group_async (group, queue, ^ {/* load Image 2 */}); dispatch_group_async (group, queue, ^ {/* load Image 3 */}); dispatch_group_queue (group, dispatch_get_main_queue (), ^ {// merge images });

 

11. What are the differences between _ block and _ weak modifiers?

Reference answer:

_ Block can be used in both ARC and MRC modes. It identifies variables outside the block and can modify the value of the variable in the block. _ Weak can only be used in ARC mode to indicate weak references. It is mainly used to prevent the introduction of circular references. 12. What are common Http status codes?

Reference answer:

302 indicates request redirection. 500 or above indicates a server error. For example, 503 indicates that the server cannot be found, and 3840 indicates that the server returns invalid JSON. 400 or above is a request Link error or cannot find the server, such as the common 404. 200 and above are correct. For example, 200 indicates that the request is normal. 100 or above indicates that the request is successfully accepted. 13. How does iOS interact with H5?

Reference answer:

The Protocol captures requests in shouldStartRequest, obtains scheme, judges pre-defined functions, and then calls native code. For example, if native is called to display a large image by defining a click image, when js receives a click, redirection adds the image url to the custom scheme, such as HYBImagePreview. 14. How to understand the shortest copy and deep copy?

Reference answer:

The so-called shallow copy refers to copying only the pointer to the object, instead of copying the reference object itself (the same memory ), the so-called deep copy refers to copying the referenced object itself (a new memory is created ).

15. Is it lazy to load data? Common scenarios?

Reference answer:

The so-called lazy loading refers to the actual loading of memory only when it is actually needed. A common scenario is to override the getter method of a property. In the getter method, you can determine whether the property has been created or loaded. If the property has not been created or loaded, you can create or load the property.

Lazy loading can optimize performance. Some functions are generally not used, but these functions occupy a large amount of memory when used. In this case, lazy loading is very good.

Common Syntax:

 
1 2 3 4 5 6 7 8 9 -(NSMutableArray *) dataSource {if (_ dataSource = nil) {_ dataSource = [[NSMutableArray alloc] init]; // Add default data, etc //...}}

 

16. Can a tableView be associated with two different data sources?

Reference answer:

Of course, multiple data sources can be associated, but multiple data sources can be used at the same time. For example, a list has two filtering functions: one is to filter the city and the other is to filter the time. The two are the two data sources. When filtering cities, the city data source is used. When filtering time, the time data source is used.

17. Add the object to the notification center. When the notification center sends a notification, the object has been released. What problems may occur?

Reference answer:

In fact, this is only a simple application of notification. Notifications are multi-to-many relationships. The main application scenario is cross-module value transfer. After an object is added to the notification center, if the object is not removed from the notification center before it is destroyed, a crash occurs when a notification is sent. This is common. Therefore, after being added to the notification center, it must be removed before release.

18. Has the framework or library been implemented for others' use? If so, let's talk about the experience in building a framework or library. If not, imagine and design the public API of the Framework, and point out what needs to be done and what needs to be paid attention, to make it easier for everyone to use your framework.

Reference answer:

Consider and design a public framework from the following perspectives:

Make sure that the external call is simple and the detailed header file annotations are provided. Ensure API coding specifications and uniform style. To ensure that the API is easy to expand, you can consider reserving parameters to ensure that there is no external dependency or the dependency should be as few as possible to ensure the purity of the Public Library (in principle, there is no external dependency) to ensure that the API is easy to maintain, there is no redundant API19. How to automatically calculate the cell height?

Reference answer:

I like the Automatic Layout of pure code. I have always used the third-party library Masonry to achieve the Automatic Layout of pure code, which is very simple to use and highly efficient. This improves the development efficiency.

With regard to the Automatic Calculation of Row Height in Masonry, the author provides extensions for swift and oc versions, both of which provide functions for Automatic Calculation of Row Height and provide caching functions, ensure that only one row is always calculated, the efficiency will be very high, and the general application will not card the screen.

Implementation principle: the id of the data model is used as the key to ensure uniqueness. How can we ensure that there is no confusion in cell multiplexing. After the data is configured, update the constraints to get the frame of the last control. Then, you can only determine the actual height required by the cell and cache it. The next time you obtain the data, you can determine whether the cell exists, if yes, return directly. Therefore, it will only be calculated once.

20. How does UITableView calculate the content height? Why does the proxy method that obtains the Row Height call data records several times When configuring data during initialization?

Reference answer:

UITableView inherits from UIScrollView, so it also has contentSize. To obtain the contentsize of tableview, You need to obtain the height of all cells and calculate the total height to obtain the contentsize. Therefore, this proxy method will be called several times during reloadData.

In order to improve efficiency, I wrote the extension for Automatic Calculation of high rows with cache, so as to ensure that only one computation is performed, to prevent the card screen. By doing this, general applications can solve the problem of card screen. You can continue to optimize Rich Text applications.

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.