iOS interview topic (i)

Source: Internet
Author: User

1. What are the applications of multithreading in real life? (Network operation and a large number of picture processing does not count)

Usually time-consuming operations are placed on the thread processing, and then back to the main thread to be displayed. Here are a few examples:

    1. We want to extract the data from the database and also to group the data to display, then we will open a sub-thread processing, processing is completed before the UI display refresh.
    2. After taking a picture, the child thread processes the image and then goes back to the main thread to display the picture. The pictures are too big to handle.
    3. Audio, video processing is manipulated on child threads
    4. When the file is large, the file operation is processed in the child thread
    5. When the client and server data synchronization, the background will be automatically synchronized

2, if the app is larger, how to reduce the size of the app? Reference Answer:
    1. Set optimization level in build setting to fastest, smallest [-os], which is set by default in release mode
    2. Set the Strip Debug Symbols During copy in build setting to Yes, which is set by default in publish mode
    3. Resource files find out all unused, remove those resource files that will never be used
    4. Compress audio for embedded apps
3. How do you deal with version compatibility issues in iterative development? Reference Answer:

Version iterations must be aware of older versions, such as adding fields or removing certain fields that are no longer in use, and not causing the app to flash back. We only talk about the program code compatibility with the new and old version of the problem, do not consider business. Because the business is required to be compatible with the background, the interface will usually have version number control for compatibility with different versions of the client.

For any app, when it can be upgraded, not all users will immediately upgrade, usually a large part of the users are unwilling to upgrade immediately. There are many reasons, such as I do not frequently upgrade, because for me, this app is not used every day, there is no need to upgrade.

So, when we develop iOS, how to go with the old version, to ensure that the new version of the increase or deletion will not affect the old version? In fact, this problem does not seem to say there is no new, old version of the problem, more importantly, the robustness of the program.

For us to do the front end, never believe that the backstage will always return the data structure we want and all the fields as originally agreed.

Assuming that the data returned by the interface is this way, we need to judge by type to make sure that there is no fallback due to an interface change returning invalid data. Of course, when the data structure returned by the interface is not the same as what we originally agreed, it is usually because of the background error, so for the program to be more robust, we should be able to accommodate the background error:

Afhttprequestoperation *op = [selfpostrequestwithurl:urlparams:paramscompletion:^ (id responseObject) {BOOL isSuccess = NO;if ([Responseobjectiskindofclass:[nsdictionaryClass]]) {nsdictionary *response = responseobject[@ "Response"];if ([responseiskindofclass:[nsdictionary class]]) {             nsarray *resultlist = Response[@ " Resultlist "];      if ([Resultlistiskindofclass:[nsarray] span class= "keyword" >class]) {        nsarray *listmodels = [ hybcosmesismodelobjectarraywithkeyvaluesarray:resultlist];         issuccess = Yes;        completion (listmodels);       }    }  }    if (!isSuccess {    //indicates an error     completion (nil);   }} errorblock:^ (Nserror *error) {  errorblock (error);}];         

When we use it, we should do the type judgment and empty processing for string, array and dictionary. Like what:

 class]])  {NSString *value = response[@ "Blogname"];  if (!kisemptystring (value)) { //do my job} nsarray *array = response[@ "Array"]; class]]) { //Do My Job}}        

For business aspects, by the background to do version control, through the interface to do add public parameters, [email protected]

? which version of the interface to invoke.

4, you and back-end server is how to interact with the reference answer:

This is a very simple question, but it's not clear to beginners. In many small companies, the front-end seems to have nothing to do, just wait backstage to give you an interface and parameter description on it, it is not clear why the backend to design this interface.

So I'm going to talk about how to interact with back-end servers:

    1. After the requirements have been determined and the development cycle has been set, the development needs to be prepared.
    2. IOS, Android and back end of the main responsible personnel after understanding the requirements, began to analyze the needs of the current requirements of the interface, whether the need for new interfaces, whether the need to change the original interface and so on. After the three-terminal unification, the back-end interface owner determines which day out interface document and interface false data. Why do we have to fix the interface with the three ends? Because even the head of the backend interface, it is not necessarily the original business and the original interface are all understood, the understanding of either side add up to determine whether it is feasible.
    3. If the app has not been developed, first develop a new app, then iOS, Android architects, or major development leaders, need to work with the back-end interface owner to analyze the requirements, and then initially write out the first version of the interface document, and then each party to take a good look at the analysis of the interface is reasonable, the parameters are reasonable, structure is reasonable and so on. The structure of the data will determine the entire network framework to build.

All right, let's talk about this.

5, how to use GCD loading more than one picture, put the picture into a blend into a picture? Reference Answer:

Use the Dispatch group to append block to the global group queue, which, if fully executed, executes the end-processing block in the main Dispatch queue.

When all requests placed in the group are complete, the block of dispatch group notify will be recalled:

0);d Ispatch_group_tgroup = Dispatch_group_create ();d ispatch_group_async (/* Load picture 1 */});d Ispatch_group_async (/* Load Picture 2 */});d Ispatch_group_async (/* Load Picture 3 */});  Dispatch_group_notify (Group, Dispatch_get_main_queue (), ^{ //Merge picture}); 
6, when using GCD, how to add a few tasks in a group of dependencies (these tasks are placed in a group) reference answer:

This is not very clear what to ask, the author looked at the GCD in the dispatch group T, and there is nothing to set the task dependencies within the same group, see Dispatch group wait this API:

longdispatch_group_wait (Dispatch_group_tgroup, dispatch_time_ttimeout);

This API waits for all of the tasks in the group to complete before proceeding to perform other tasks. It waits for the task to execute synchronously. For example, A, B, C, d four tasks, require A, b after execution, C, D to start execution, then you can do this:

0);d Ispatch_group_tgroup = Dispatch_group_create (); Dispatch_group_async (/* Task A */}); Dispatch_group_async (/* task B */}); Dispatch_group_notify (Group,    Dispatch_get_main_queue (), ^{dispatch_group_async (/* task c */});  Dispatch_group_async (/* Task D */});}); 

Or you can do this:

Dispatch_queue_tqueue = Dispatch_get_global_queue (Dispatch_queue_priority_default,0);d Ispatch_group_tgroup = Dispatch_group_create ();  dispatch_group_async ( group, queue, ^{/* Task A */}); Dispatch_group_async ( group, queue, ^{/* task b */}); //synchronous wait for A, b execution dispatch_group_wait (group, dispatch_time_forever); Dispatch_release (group)  //re-create group group = Dispatch_group_create ();d ispatch_group_async (group, queue, ^{/* task c * * });d Ispatch_group_async (group, queue, ^{/* task d */});d Ispatch_group_ Notify (group, Dispatch_get_main_queue (), ^{    / /C, D after the completion of the implementation, want to do why go to it});                  

I do not know the author's understanding of the topic is in place, the above code is readily written, maybe the word will be written wrong ~ ~ ~

7 How iOS displays normally when a user changes their avatar

Programme I

The solution that I can think of:

The author of this question, the first thought is through the image of the summary validation. When the server returns the user information in the interface, along with the image summary (MD5) value is also issued to the client, and each time the app logs in, the server will return the latest user information, the client will cache the local user picture, also generate a digest (MD5) five, and the server returned by the MD5 value of the comparison, If the same means no avatar has not been modified, if not the same, the Avatar has been modified.

Cons: You can only update if you sign in again or the app is automatically logged in in the background. In other words, if the user does not sign out, or does not expire and does not log in automatically, the avatar is not updated.

Programme II

Collect your plans on Weibo. Add a parameter version to the URL, and when the image is modified, the version of the URL changes, and the image is re-downloaded for caching.

Cons: Similar to scenario one, requires data to be re-requested to get the latest URL.

Programme III

When modifying a picture, it is not necessary to use the same name, so the link path is the same, but it cannot be found because of a different name. At this point, the picture is retrieved instead of cached. The file name can be uploaded with the prefix, such as avatar-3/v1.jpg, updated to Avatar-3/v2.jpg.

Programme IV

The client adds the If-modified-since field to the request header, indicating that the latest file resource is requested after this time, and the server will return the Last-modified field in response header to indicate the last modification time.

iOS interview topic (i)

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.