IOS interview question summary 1

1. The difference between mvc and mvp and the advantages and disadvantages of use

The V in MVP refers to ViewController and View in iOS. MVP splits the MVC ViewController: the logical processing part of the view data is P, and the remaining part of the ViewController is merged with the View into V. Communication between V and P is carried out through Protocol.

MVP realizes the decoupling of each module and has better testability. But the overall amount of code is larger than MVC.
In addition, iOS MVC is more suitable for rapid development, that is, projects with smaller code sizes. Therefore, changing the simple MVC Demo to MVP will seem clumsy.

2. After iOS is packaged successfully, it will flash back and black screen when running on iPhone

One is the certificate error, the other is that the current device is not in the developer's corresponding account.

3. OC's dictionary implementation principle

Hash table:

Hash: 1、Hash algorithm 2、md5 3、SHA1...

You can write a hash number yourself, sort the name key by 26 first letters, you can use 13 grids for storage, if the first letter is the same, you can add an increment, H=(H(key)+d)Mod m, d starts from 1 and modulates the whole quantity m=13, doing an increase operation. In practice, if there are fewer repetitions in the grid, the better the algorithm is. The higher the efficiency.

4. The difference between the message sending mechanism and the message forwarding mechanism in iOS

Message sending mechanism:

The function call of OC becomes the message sending. Belongs to the dynamic calling process. It is not possible to decide which function to actually call during compilation (it turns out that OC can call any function in the compilation phase, even if this function is not implemented, it will not report an error as long as it is declared. The C language will report an error during the compilation phase) . Only when it is actually running will the corresponding function be found and called according to the function name.

Message forwarding mechanism:

1. Method resolution method analysis processing stage
2. Fast forwarding fast forwarding stage
3. Normal forwarding regular forwarding stage

5. Communication between ancestors 

There are a lot of componentization solutions discussed in the iOS industry, in general there are three.

 

  • Protocol Registration Scheme
  • URL registration scheme
  • Target-Action runtime calling plan

MGJRoute solution

URL registration program path components of the App's mushroom Street have made it very clear that you can go to the next

principle:

Register the service through the url, other places through the url, get the service framework and maintain a url-block form

Features:

  • URL maintenance cost is high, hard decoding
  • Services can be called/registered anywhere inside the component, there is no need to unify component interface services
  • Every business component needs to rely on this framework

6. How does SDWebImage clean up the cache?

1. Delete according to chronological order, and delete after 7 days.

2. Save the ones that were not deleted before in chronological order, and delete them according to the custom maximum cache until half of the maximum cache.

Cache calculation, its unit is byte

[[[SDWebImageManager sharedManager] imageCache]getSize];

Number of cached pictures

[[[SDWebImageManager sharedManager] imageCache] getDiskCount];

Cache cleaning, the first is memory cache, the second is hard disk cache

[[[SDWebImageManager sharedManager] imageCache] clearMemory];  
[[[SDWebImageManager sharedManager] imageCache] clearDisk];

7. How does SDWebImage handle received memory warnings?

AutoPurgeCache inherits from NSCache to automatically clear the cache and call the removeAllObjects method of NSCache.

8. How to calculate the cost of pictures in SDWebImage?

Cache size

/**
 * Get the size used by the disk cache
 */
- (NSUInteger)getSize;
// 注意:返回值单位为字节
// 具体实现
- (NSUInteger)getSize {
    __block NSUInteger size = 0;
    dispatch_sync(self.ioQueue, ^{
        NSDirectoryEnumerator *fileEnumerator = [_fileManager enumeratorAtPath:self.diskCachePath];
        for (NSString *fileName in fileEnumerator) {
            NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];
            NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
            size += [attrs fileSize];
        }
    });
    return size;
}

9. What is the difference between clear and clean in SDWebImage?
 

clear

   delete all

clean

   Partially deleted 

  1. Delete according to chronological order and delete after 7 days.

   2. Save the ones that were not deleted before in chronological order, and delete them according to the custom maximum cache until half of the maximum cache.

 

 

Guess you like

Origin blog.csdn.net/Draven__/article/details/90110217