IOS development pen questions for a company in iOS, ios pen questions for a company

Source: Internet
Author: User

IOS written test questions for a company of iOS, IOS written test questions for a company

 

The reference answer is not unique, you can answer according to your own understanding, there is no need to be the same as the author. Refer to the author's answer, maybe it will bring you inspiration!

1. Deduplicate the elements in the array
E.g:

NSArray * array = @ [@ "12-11", @ "12-11", @ "12-11", @ "12-12", @ "12-13", @ "12-14"];
Reference answer:

The first method: open up a new memory space, and then determine whether it exists, if not, add it to the array, and the order of obtaining the final result does not change. Efficiency analysis: The time complexity is O (n ^ 2):
NSMutableArray * resultArray = [[NSMutableArray alloc] initWithCapacity: array.count];
// An outer loop
for (NSString * item in array) {
   // Call -containsObject: The essence is to loop to judge, so it is essentially a double-layer traversal
   // The time complexity is O (n ^ 2) instead of O (n)
    if (! [resultArray containsObject: item]) {
      [resultArray addObject: item];
    }
}
NSLog (@ "resultArray:% @", resultArray);
The second method: use NSDictionary to remove duplicates. When setting the key-value, the dictionary updates the value if it already exists, inserts the value if it does not exist, and then obtains allValues. If ordering is not required, this method can be used. If ordering is required, it must be sorted. Efficiency analysis: It only takes one cycle to complete putting in the dictionary. If ordering is not required, the time complexity is O (n). If sorting is required, the efficiency depends on the sorting algorithm:
NSMutableDictionary * resultDict = [[NSMutableDictionary alloc] initWithCapacity: array.count];
for (NSString * item in array) {
    [resultDict setObject: item forKey: item];
}
NSArray * resultArray = resultDict.allValues;
NSLog (@ "% @", resultArray);
If you need to sort in the original ascending order, you can do this:

resultArray = [resultArray sortedArrayUsingComparator: ^ NSComparisonResult (id _Nonnull obj1, id _Nonnull obj2) {
  NSString * item1 = obj1;
  NSString * item2 = obj2;
  return [item1 compare: item2 options: NSLiteralSearch];
}];
NSLog (@ "% @", resultArray);
The third method: use the characteristics of the set NSSet (determinism, disorder, mutual dissimilarity), and put it in the set to automatically remove the duplicates. But it has the same disorder as the dictionary, and the order of the results is no longer the same as the original. If ordering is not required, the efficiency of using this method and dictionary should be similar. Efficiency analysis: The time complexity is O (n):
NSSet * set = [NSSet setWithArray: array];
NSArray * resultArray = [set allObjects];
NSLog (@ "% @", resultArray);
If ordering is required, it must be sorted, such as sorting in ascending order here:

resultArray = [resultArray sortedArrayUsingComparator: ^ NSComparisonResult (id _Nonnull obj1, id _Nonnull obj2) {
  NSString * item1 = obj1;
  NSString * item2 = obj2;
  return [item1 compare: item2 options: NSLiteralSearch];
}];
NSLog (@ "% @", resultArray);
The above three methods are what I can think of. If you have a better way, please point it out in the comments.

2. Talk about the characteristics and functions of the following elements
NSArray, NSSet, NSDictionary and NSMutableArray, NSMutableSet, NSMutableDictionary
Reference answer:

characteristic:

NSArray represents an immutable array, which is an ordered set of elements. It can only store object types. You can directly access elements through indexes, and element types can be different, but you cannot add, delete, or modify operations; NSMutableArray is a variable array, which can be Add, delete, and modify operations. Querying the value by index is fast, but the efficiency of inserting and deleting is very low.
NSSet represents an immutable collection, which has the characteristics of determinism, mutualism, and disorder. It can only be accessed but cannot modify the collection; NSMutableSet represents a variable collection, which can be added, deleted, or modified. Collections are quickly queried by value, and insert and delete operations are extremely fast.
NSDictionary represents an immutable dictionary, which has the characteristics of disorder. The value corresponding to each key is unique, and the value can be obtained directly through the key; NSMutableDictionary represents a variable dictionary, which can add, delete, and modify the dictionary. Querying values by key, inserting, and deleting values are all fast.
effect:

Arrays are used to process a set of ordered data sets. For example, the dataSource of a commonly used list requires ordering, which can be directly accessed by index, which is highly efficient.
Collections are required to be deterministic, mutually different, and disordered, and are rarely used in iOS development. The author also has no idea how to explain its role.
The dictionary is a key-value pair data set. The operation of the dictionary is extremely efficient. The time complexity is constant, but the values are unordered. In iOS, the common JSON to dictionary, dictionary to model is one of the applications.
3. Briefly describe XIB and Storyboards, and talk about their advantages and disadvantages.
Reference answer:

The author prefers pure code development, so the reference answers provided may have some personal feelings, but I still tell everyone what I think.

advantage:

XIB: It provides a visual interface before compilation. You can drag the control directly or add constraints directly to the control, which is more intuitive, and the code for creating the control is less in the class file, which is really a lot simplified. Usually each XIB corresponds A class.
Storyboard: Provides a visual interface before dragging, draggable controls, and constraints. It is more intuitive during development, and a storyboard can have many interfaces, each interface corresponds to a class file, and through storybard, you can intuitively see the entire App structure.
Disadvantages:

XIB: When the requirements change, the XIB needs to be modified greatly, and sometimes the constraints need to be added again, resulting in a longer development cycle. XIB loading is naturally slower than pure code. For more complex logic control when displaying different content in different states, it is more difficult to use XIB. When a multi-person team or multi-team development, if the XIB file is launched, it is easy to cause conflicts, and it is relatively difficult to resolve conflicts.
Storyboard: When requirements change, you need to modify the constraints of the corresponding interface on the storyboard. Like XIB, you may need to add constraints again, or adding constraints will cause a lot of conflicts, especially for multi-team development. It is more difficult for complex logic to control different display contents. When a multi-person team or multi-team development, everyone will modify a storyboard at the same time, resulting in a lot of conflicts, it is very difficult to resolve.
4. Please convert the formatted date of the string "2015-04-10" to NSDate type
Reference answer:

NSString * timeStr = @ "2015-04-10";
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @ "yyyy-MM-dd";
formatter.timeZone = [NSTimeZone defaultTimeZone];
NSDate * date = [formatter dateFromString: timeStr];
// 2015-04-09 16:00:00 +0000
NSLog (@ "% @", date);
5. How to achieve the development by mixing HTML5 in the App. What are the advantages and disadvantages of using HTML5 in App?
Reference answer:

In iOS, it is usually implemented by UIWebView. Of course, after iOS8, WKWebView can be used. There are several implementation methods:

Intercept by implementing the proxy method of UIWebView, determine whether the scheme is agreed, and then iOS calls the local related API to achieve:
-(BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType;
After iOS7, it can be implemented directly through the JavaScripteCore library, by injecting an object into the JS DOM, and this object corresponds to an instance of a class in our iOS. For more details, please read:

OC JavaScriptCore interacts with js
New features of WKWebView and JS interaction
Swift JavaScriptCore interacts with JS
Can be achieved through WebViewJavascriptBridge. How to use it, please go to other blogs to search!

Advantages and disadvantages:

The response of iOS joining H5 is much slower than native, and the experience is not very good, which is a disadvantage.
The addition of H5 to iOS can embed other function entrances, which can be changed at any time, and you can go online without updating the version. This is the biggest advantage.
6. Please describe the difference between synchronous and asynchronous.
Reference answer:

First of all, we have to make it clear that both synchronous and asynchronous are used in threads. In iOS development, such as when requesting data from the network, if a synchronous request is used, only when the request is successful or the request fails and the response is returned, can you continue to go down, that is, you can access other resources (which will block the thread). When the network requests data asynchronously, it will not block the thread. After the request is called, it can continue to execute without waiting for the result of the request to continue.

the difference:

Thread synchronization: When multiple threads access the same resource, other threads can only start accessing (blocked) after the access of the currently accessing thread ends.
Thread asynchrony: When multiple threads are accessing competing resources, they can access other resources while they are idle (not blocked).
7. Please briefly describe the principle of using queues and multi-threads.
Reference answer:

The queue is divided into the following types in iOS:

Serial queue: tasks in the queue will only be executed sequentially
dispatch_queue_t q = dispatch_queue_create ("...", DISPATCH_QUEUE_SERIAL);
Parallel queue: tasks in the queue are usually executed concurrently
dispatch_queue_t q = dispatch_queue_create ("......", DISPATCH_QUEUE_CONCURRENT);
Global Queue: It is systematic, it can be used directly (GET); similar to parallel queue
dispatch_queue_t q = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
Main queue: each application corresponds to a unique main queue, just GET directly; in multi-threaded development, use the main queue to update the UI
dispatch_queue_t q = dispatch_get_main_queue ();
The above four are for GCD. The tasks in the serial queue can only be executed one by one. Before the previous one is not completed, the next one can only wait. Parallel queues can execute tasks concurrently, so the order of execution among multiple tasks cannot be determined. When a new task is added, it is left to the GCD to determine whether to create a new thread.

You can read the picture multi-threaded, perhaps more clearly:

Illustrated multithreading for iOS
8. Describe the aspects of iOS memory management, including the use and optimization of memory in development. What issues should we pay attention to in development.
Reference answer:

Memory management guidelines: Whoever strongly references it will decrement the reference count when it is no longer used.

The following are common aspects of memory usage and optimization:

Reuse issues: such as UITableViewCells, UICollectionViewCells, UITableViewHeaderFooterViews

Set the correct reuseIdentifier for full reuse.

Try to set the views to opaque: when opque is NO, the translucency of the layer depends on the picture and the layer synthesized by itself as the result, which can improve performance.

Don't use too complicated XIB / Storyboard: when loading, all resources required by XIB / storyboard, including pictures, will be loaded into memory, even if it will be used in the future. Compared to lazy loading written in pure code, performance and memory are much worse.

Choose the right data structure: Learning to choose the most suitable array structure for the business scenario is the basis for writing efficient code. For example, an array: an ordered set of values. Querying using indexes is fast, querying using values is slow, and inserting / deleting is slow. Dictionary: Store key-value pairs. It is faster to search by key. Collection: An unordered set of values, using values to find quickly, insert / delete quickly.

gzip / zip compression: when downloading related attachments from the server, you can download them after gzip / zip compression, making the memory smaller and the download speed faster.

Lazy loading: For data that should not be used, use lazy loading. For views that do not need to be displayed immediately, use lazy loading. For example, the prompt interface displayed when a network request fails may never be used, so you should use lazy loading.

Data caching: The line height of the cell should be cached, so that when reloading the data, the efficiency is also very high. For those network data, which need not be requested every time, they should be cached, can be written to the database, or can be stored through the plist file.

Handle memory warnings: generally handle memory warnings in the base class and release related unused resources immediately

Reuse large overhead objects: Some objects are slow to initialize, such as NSDateFormatter and NSCalendar, but they inevitably need to be used. It is usually stored as an attribute to prevent repeated creation.

Avoid repeated data processing: Many applications need to load data from the server, often in JSON or XML format. It is important to use the same data structure on the server and the client.

Use Autorelease Pool: When certain loops create temporary variables to process data, the pool is automatically released to ensure that memory can be released in a timely manner.

Correctly select the image loading method: read the detailed reading UIImage loading method

9. What is the plist file for? It is generally used to deal with some problems.
Reference answer:

plist is a unique file format in the iOS system. Our commonly used NSUserDefaults preferences are essentially plist file operations. The plist file is used to store data persistently.

We usually use it to store preference settings, as well as small amounts of data with complex array structures that are not suitable for storing databases. For example, if we want to store the names and ids of cities across the country, then we should prefer to choose plist for direct persistent storage, because it is simpler.

10. A certain amount of data is cached in iOS so that it can be executed quickly next time, so where will the data be stored and how many storage methods are there?
Reference answer:

Preferences (NSUserDefaults)
plist file storage
Archive
SQLite3
Core Data
For details, please read: iOS commonly used persistent storage

11. Please simply write the SQL statements for adding, deleting, modifying and checking.
Reference answer:

The simple operation of the database is still possible, the university can not learn it in vain.

increase:

insert into tb_blogs (name, url) values ('Big Brother's technical blog', 'http: //101.200.209.244');
delete:

delete from tb_blogs where blogid = 1;
change:

update tb_blogs set url = '101.200.209.244' where blogid = 1;
check:

select name, url from tb_blogs where blogid = 1;
12. When submitting to Apple for review, what problems were encountered and how to deal with the rejected problems.

Reference answer:

For the author, the submitted app has not been rejected. However, in the groups maintained by the author, friends often asked about the rejected solutions. Fortunately, I also know a little English, and I can help them translate the reasons for rejection of Apple ’s feedback and suggestions.

Here are just a few of the most common reasons for rejection:

The most common thing is that there is a virtual item transaction in the app, but it is not because of in-house purchases that lead to rejection.
Audio apps or apps that use audio are rejected because of copyright issues
App will flash back and be rejected
At last
On this night, all the answers were put out by the author to spend a lot of time to sort out, and read and cherish it! If the reference answers provided are different from your ideas, welcome to the group to communicate, or you can directly feedback in the comments.

It's quiet at night ~


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.