"Interview" IOS Development Questions (III.)

Source: Internet
Author: User
Tags notification center

1. What are the iOS data persistence storage scenarios?

Reference Answer:

    • Plist Property list storage (e.g. Nsuserdefaults)
    • File storage (such as binary data written to a file store, which is stored by Nsfilemanager to write an archive of downloaded binary data)
    • Nskeydearchiver Archive Storage, the most common is automated archive/solution processing, want to learn how to implement automated archiving/solution, can be
    • Database SQLite3 storage (e.g. Fmdb, Core Data)
2. What is the directory structure of the sandbox? What kind of occasions are they generally used for?

Reference Answer:

    • Application: Store program source files, before the shelves are digitally signed, after the shelves can not be modified
    • Documents: Save the data that needs to be persisted at run time, which is backed up when itunes synchronizes the device. For example, a game app can save a game archive in that directory
    • TMP: Save the temporary data that is required at run time, and then delete the corresponding file from the directory when you are finished. When the app is not running, the system may also purge files in that directory. itunes does not back up this directory when syncing the device
    • Library/caches: Save when the app is running? data that needs to be persisted, itunes does not back up the directory when syncing the device. Non-critical data with large storage volumes and no backup required, such as network data cache storage to Caches
    • Library/preference: Save all of your app's preferences, such as iOS settings (settings)? This directory will look for settings information. This directory is backed up when itunes syncs the device
3, #define定义的宏和const定义的常量有什么区别?

Reference Answer:

    • #define定义宏的指令, the program will simply replace the content defined by # define in the preprocessing phase. Therefore, when the program runs, the constant table does not have a macro defined by # define, the system does not allocate memory for it, and the data type is not checked at compile time, the probability of error is greater.
    • Const-defined constants, which are stored in a constant table when the program is run, allocate memory for it and type checking at compile time.
    • #define定义表达式时要注意 "Edge effect", as defined below:

1 2 3 4 #define N 2 + 3//The N value we expect is 5, so we use ninta = N / 2; //The value of a is 2.5, but actually the value of a is 3.5

4. What are the common scenarios where memory loop references occur?

Reference Answer:

    • Timer (Nstimer): Nstimer is often used as a member variable for a class, and Nstimer is initialized to specify self as target, which can easily cause a circular reference (self->timer->self). In addition, if the timer is always in the validate state, its reference count will always be greater than 0, so the invalidate method should be called first after the timer is no longer used
    • Block usage: block will use a strong reference (ARC) or Retaincount 1 (non-ARC) to the object used within the block at copy time. Improper use of blocks in both arc and non-ARC environments can cause circular reference problems, typically by a class that uses block as its own property variable, and then the class itself in the block's method body, which simply says 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)
    • Agent (delegate): There is a circular reference problem on the delegation issue is a cliché, the killer of the problem is also simple to cry, a word tactic: declare delegate when you use assign (MRC) or weak (ARC), Do not have the hand to play a little bit retain or strong, after all, this basic can't escape the circular reference!
5. Weak self in block, is it necessary to add it at any time?

Reference Answer:

Not everything needs to be added at any time, but it always seems good to add at any time. Circular reference problems occur whenever a structure chain such as Self->block->self.property/self->_ivar appears. With a good analysis, you can infer whether there is a circular reference problem.

6, the GCD queue, the main queue executed code must be in 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 code executed is executed in the main thread. If created in a child thread, it is not executed in the main thread.
    • The main queue is in the main thread, so it must be executed in the main thread. Get the main queue on it, do not need us to create, get the way by calling method Dispatchgetmain_queue to get.
7. The member variable (not the attribute) declared in the header file can be accessed directly externally?

Reference Answer:

The member variables declared by the header file cannot be accessed directly externally, and the getter method that provides the member variable is required for external access. Properties have been directly generated for us by the Getter method, so the properties can be accessed directly externally.

8. What is the difference between TCP and UDP?

Reference Answer:

    • TCP: Connection-oriented, reliable transmission (guaranteed data correctness, guaranteed data order transmission), for transmitting large amounts of data (stream mode), slow, to establish a connection requires more overhead (time, system resources).
    • UDP: For non-connected, unreliable transmission, for transmitting a small amount of data (packet mode), fast, transmission is the message.
9. What are the differences between MD5 and Base64, and what are the respective usage scenarios?

Reference Answer:

Encryption-related functions are almost always used in MD5 and Base64, both of which are most commonly used in real-world development.

    • MD5: is an irreversible digest algorithm for generating abstracts that cannot be reversed to get the original text. A common use is to generate a 32-bit digest that verifies the validity of the data. For example, in a network request interface, by generating summaries of all the parameters, the client and the server use the same rules to generate summaries, which can be tamper-proof. As another example, when downloading a file, a summary of the generated file is used to verify that the file is corrupted.
    • Base64: Belongs to the encryption algorithm, is reversible, after encode, can decode get the original text. In the development, some companies upload images using the image is converted into Base64 string, and then upload. When doing encryption-related functions, data is usually base64 encrypted/decrypted.
10, send 10 network requests, and then receive all the responses after the follow-up operation, how to achieve?

Reference Answer:

From the analysis of the topic, 10 requests must be completed before performing a certain function. For example, after downloading the 10 image to synthesize a large image, you need to complete the asynchronous full download before merging into a larger image.

Practice: By dispatch_group_t, each request is put into the group, and the merge into a large map is implemented in Dispatch_group_notify.

1 2 3 4 5 6 7 8 9 Ten  dispatch_queue_t queue dispatch_get_global_queue ( dispatch_queue_priority_default , 0 dispatch_group_t group dispatch_group_create ( Span class= "Crayon-sy" style= "" >) ; dispatch_group_async ( group , queue ^ Span class= "Crayon-sy" style= "" >{ / * Load Image 1 */ } " dispatch_group_async ( group , queue ^ Span class= "Crayon-sy" style= "" >{ / * Load Image 2 */ } " dispatch_group_async ( group , queue ^ Span class= "Crayon-sy" style= "" >{ / * Load Image 3 */ } " dispatch_group_notify(Group,dispatch_get_main_queue (),^{// merge pictures }); 

11. What are the differences between __block and __weak modifiers?

Reference Answer:

    • __block can be used either in arc or MRC mode, and it is used to identify variables outside the block that can be modified within the block using the value of the variable.
    • __weak can only be used in ARC mode, indicating weak references, primarily to prevent circular references from being introduced.
12. What are the common HTTP status codes?

Reference Answer:

    • 302 is request redirection.
    • 500 and above are server errors, such as 503 indicating that the server was not found, and 3840 indicates that the server returned an invalid JSON.
    • 400 and above is a request link error or cannot find the server, such as the common 404.
    • 200 and above are correct, as the common 200 indicates that the request is normal.
    • 100 and above are the requests accepted successfully.
13. What are the ways iOS interacts with H5?

Reference Answer:

    • The request is captured through the protocol in Shouldstartrequest, the scheme is obtained to determine the pre-defined function, and then the native code is called. For example, the definition of click on the image call native to display a large image, then JS received click, redirect the image URL to add a custom scheme, such as hybimagepreview://.
14, how to shallow copy and deep copy of understanding?

Reference Answer:

A shallow copy is a copy of a pointer to an object, not the reference object itself (the same memory), whereas a deep copy refers to the copy of the Reference object itself (a newly created memory).

15, use is lazy loading? Common scenarios?

Reference Answer:

Lazy loading refers to the actual loading of memory when it is really needed. The common scenario is to override the property's Getter method, to determine whether it has been created or loaded in the getter method, created or loaded if it has not been created or has not been loaded.

Lazy loading can optimize performance, some features will not be used in general, but the use of these features will occupy a large amount of memory, when using lazy loading is very good.

Common wording:

1 2 3 4 5 6 7 8 9   nsmutablearray ) datasource {    if ( _ DataSource == nil ) Span class= "crayon-h" style= "" > { _datasource=[ [Nsmutablearray alloc] init]; // Add default data, etc.     // ...  }} 

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

Reference Answer:

Of course, there are several different data sources that can be associated, but different data sources are used at the same time. For example, a list has two filter functions, one is to filter the city, and the other is to filter the time, then these two are two data sources. When a city is filtered, the city data source is used, and when the time is filtered, the time data source is used.

17, the object is added to the notification center, when the notification center sent a notification, the object has been released, what might be the problem?

Reference Answer:

In fact, this is only a simple application of notice. Notifications are many-to-many relationships, and the main use scenario is to pass values across modules. When an object is added to the notification hub, the object is not removed from the notification hub until the object is destroyed, causing a crash when the notification is sent. This is very common. So, after you add to the notification hub, be sure to remove it before you release it.

18. Have you ever implemented a framework or library for others to use? If so, talk about the experience of building a framework or library, and if not, visualize and design the API for the public of the framework, and point out what you probably need to do and what you need to pay attention to to make it easier for everyone to use your framework.

Reference Answer:

Consider and design a public framework from the following perspectives:

    • Ensure that external calls are simple and that detailed header file comment descriptions are guaranteed.
    • Ensure API coding specifications to ensure consistent style.
    • Make sure the API is easy to expand, consider reserving parameters
    • Ensure that no external dependencies or dependencies are as small as possible to ensure the purity of the public library (in principle, no external dependencies)
    • Ensure easy maintenance with no redundant APIs
19, how to automatically calculate the height of the cell?

Reference Answer:

The author likes the pure Code automatic layout, has been using masonry this third-party library to realize the pure Code automatic layout, the use is very simple, and the efficiency is also very high. Developed to improve the efficiency of development.

About masonry automatic calculation of row height, the author provides the Swift version and the OC version of the extension, these two versions provide automatic calculation of row height, and with the cache function, to ensure that always only calculate the row height, efficiency will be high, the general application will not be the card screen.

Implementation principle: With the ID of the data model as key, to ensure that the unique, how to ensure that the reuse of the cell without confusion. After the data is configured, by updating the constraint, the frame of the last control can be determined only by determining the height that the cell actually needs, and caching it, the next time it is acquired, the judgment exists, and if it exists, it returns directly. Therefore, it is calculated only once.

20. How does the UITableView calculate the content height? Why does the proxy method that gets the row height call the data bar several times when configuring data at initialization time?

Reference Answer:

UITableView is inherited from the Uiscrollview, so there are contentsize. To get TableView's contentsize, you need to get all the cell heights to calculate the total height in order to get contentsize. Therefore, when reloaddata, the proxy method data bar is called several times.

In order to improve efficiency, I wrote the extension for automatic calculation of row height, and with the cache, to ensure that only the calculation once, to prevent freezing. To do this, the general application can solve the problem of the card screen. For rich text more applications, you can continue to optimize OH.

"Interview" IOS Development Questions (III.)

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.