当前位置:网站首页>IOS interview

IOS interview

2022-07-01 12:13:00 Minjiang Xiaozhang

iOS interview

Intelligence questions

64 horse 8 A track , At least how many rounds are needed to select the fastest 4 horse

11 Time 
 reason : 64 batch  8 One at a time   Eight times in total 
 The last four groups are eliminated , The first four groups are promoted .  The last four of the first four groups are eliminated and the first four are promoted .
 At this time, there are 4*4  altogether 16 Approve horses 
 The last three in the fourth place group are eliminated 、 The last two in the third place group are eliminated 、 The last player in the second place group is eliminated 
 At this time, there are 4+3+2+1 = 10   At this time, the first place in the first group must be promoted   So there are 9 horse 
 The remaining nine run twice 
 therefore 8+1+2 = 11 Time 

Two people play a coin toss , Whoever throws to the front first wins . Then the probability of the first thrower winning is ().

2/3

 The first 1 Basheng  1/2 (A just )
 The first 2 Basheng  1/2 * 1/2 * 1/2A back B back A just )
 The first n Basheng  1/2^(2n-1)
A Introduction to victory , Is the sum of the above probabilities .
 Sum formula according to the sequence of proportional numbers , When  n  At infinity , Its value is  2/3.

Fundamentals of computer

The three elements of object orientation ?

 Encapsulation inheritance polymorphism 

Five basic principles of object-oriented ?

 The principle of single accusation 、 Opening and closing principle 、 The principle of Dependence Inversion 、 Dimitar's law 、 Richter's law of substitution 

The difference between heap and stack ?

1. The stack area (stack): Release is automatically allocated by the compiler , Stores the parameter values of the function , Local variable equivalence . It operates like a stack in a data structure .

2. Heap area (heap): Release is usually assigned by the programmer , If programmers don't release , May cause a memory leak . It is similar to a linked list .

HTTP and HTTPS difference ?

http  and  https  It USES a completely different connection , The ports are different , The former is  80, The latter is  443.https  yes http+ssl( Secure socket layer )

OSI Seven layer model, five layer model and corresponding protocols ?

OSI Seven layer network model TCP/IP Five layer network model Corresponding network protocol
application layer application layer HTTP、TFTP、FTP、NFS、WAIS、SMTP
The presentation layer application layer Telnet、Rlogin、SNMP、Gopher
The session layer application layer SMTP、DNSr
Transport layer Transport layer TCP、UDP
The network layer The network layer IP、ICMP、UUCP、ARP、RARP、AKP
Data link layer Data link layer FDDI、Ethernet、Arpanet、PDN、SLIP、PPP
The physical layer The physical layer IEEE 802.1A、IEEE802.2 To IEEE 802.11

HTTP Header fields include ? Say a few status codes ?

 Universal head 、 Request header 、 Response header and entity header .
100: The client should continue to send the rest of the request 
200: Request succeeded 
304: Since last request , The requested page has not been modified . When the server returns this response , Page content will not be returned .( cache )
400: Semantically incorrect 
404: request was aborted , The requested resource was not found on the server 
500: The server encountered an unexpected situation , Unable to complete request 
509: Server reaches bandwidth limit 

https Must it be safe ?

https Not all are safe , Some websites use self signed certificates .
 Self signed certificate refers to any organization or individual that is not trusted , Issued by the tool itself SSL certificate . Not from a public certification authority (CA) The certificate applied for there , There is no third-party supervision and audit , Not trusted by browsers and operating systems , It is often used to forge certificates for man in the middle attacks , hijacked SSL Encrypted traffic .

TCP and UDP The difference between ?

TCP Is connection oriented 、 reliable 、 The transmission rate is slow 、 Transfer a lot of data 
UDP Is for connectionless 、 unreliable 、 Small amount of data 、 fast 

TCP Three handshakes process understanding ?

 The first handshake : When establishing a connection , The client sends syn package (syn=j) To the server , And enter SYN_SENT state , Wait for server to confirm ;
 The second handshake : Server received syn package , Must confirm customer's SYN(ack=j+1), At the same time, I also send a SYN package (syn=k), namely SYN+ACK package .
 The third handshake : Client receives server's SYN+ACK package , Send confirmation package to server ACK(ack=k+1),

TCP Understanding the process of four waves ?

 Please add a picture description


 Four handshakes means termination TCP Connection agreement , Four packets need to be sent between the client and the server 

 First wave : The active shutdown party sends the first packet , among FIN Sign bit is 1, Send sequence number seq by X.
 Second wave : Passive closing party receives FIN Send the second packet after the packet , Where the sending sequence number is seq by Z, Receiving sequence number ack by X+1.
 Third wave : The passive shutdown party sends a third packet , among FIN Sign bit is 1, Send sequence number seq by Y, Receiving sequence number ack by X.
 Fourth wave : The active shutdown party sends the fourth packet , The sending sequence number is X, The receiving sequence number is Y. thus , Finish four waves .

Why three handshakes when connecting , It's four handshakes when it's closed ?

 answer : Because when Server End receipt Client Terminal SYN After connecting the request message , It can be sent directly SYN+ACK message . among ACK Messages are used to answer ,SYN Messages are used to synchronize . But when you close the connection , When Server End receipt FIN When the message , It's not likely to shut down immediately SOCKET, So you can only reply one first ACK message , tell Client End ," You sent it FIN I received the message ". Only when I Server All messages are sent , I can send FIN message , So we can't send . So it takes four steps to shake hands .

Input URL What happened after ?

1DNS Domain name resolution 
2、 establish TCP
3、 send out HTTP request 
4、 Server processing request 
5、 Return the response result 
6、 close TCP link 
7、 Browser parsing HTML
8、 Browser layout rendering 

What is a deadlock ?

 Deadlock refers to the execution of two or more processes , A blocking phenomenon caused by competition for resources or communication with each other , If there is no external force , They will not be able to move forward . At this point, the system is said to be in a deadlock state or the system has produced a deadlock , These processes that are always waiting for each other are called deadlock processes 

iOS Development related

Basic data type memory footprint ?

 Please add a picture description

Java,python,OC Which one is more efficient ?

OC, Generate machine code directly .java Is static language static compilation , Direct execution . and python Is a dynamically typed language , Compile and execute .

OC Is there multiple inheritance ?

 There must not be 

What are the ways to transfer values between pages ?

( Public attribute , Public methods and protocols ,block Pass value , notice ,extern Global variable transfer value ,NSUserDefault Simple data storage transfer value )

iOS About the thread of sending and receiving notifications ?

Notification  It is completed in the same thread post and observer To deal with .iOS The thread of the method to receive the notification has nothing to do with the thread when registering the notification , It is related to the thread where the notification is sent ( It is consistent with the thread where the notification is sent ),  If the notification sent by the sub thread   Refresh when receiving the notification UI operation   Remember to return to the main thread 

iOS Data local persistence method ?

plist file ( serialize )、preference( preferences )、NSKeyedArchiver( file )、SQLite3FMDBCoreData、 Sandbox 

Directory structure of sandbox ?

1Documents  Catalog : You should write all application data files to this directory . This directory is used to store user data . This path can be implemented by configuration iTunes Shared files . Can be iTunes Backup .

2AppName.app  Catalog : This is the package directory for the application , Contains the application itself . Because applications have to be signed , So you can't modify the contents of this directory at run time , Otherwise, the application may not start .

3Library  Catalog : There are two subdirectories under this directory :
Preferences  Catalog : Contains the preferences file for the application . You should not create preference files directly , It should use NSUserDefaults Class to get and set the preferences of the application .
Caches  Catalog : It is used to store the supporting files dedicated to the application , Save the information needed to restart the application .
 You can create subfolders . It can be used to place data that you want to be backed up but don't want to be seen by users . The folder under this path , except Caches outside , Will be iTunes Backup .

4、tmp  Catalog : This directory is used to store temporary files , Save information that you don't need when the application starts again . Files in this path will not be deleted iTunes Backup .

Property(nonatomatic, copy) NSMutableArray What's the problem? ?

addObject、removeobject It could break down 

The attribute of the agent modifies the keyword ?

@property(nonatomic,assign)

UIViewController Life cycle of

 Arrange in order of execution :
initWithCoder: adopt nib Trigger on file initialization .
awakeFromNib:nib When the file is loaded , There will be a awakeFromNib The news came to nib Every object in the file .      
loadView: Start loading the view controller's own view.
viewDidLoad: View controller's view Loading completed .  
viewWillAppear: View controller's view Will be displayed in window On .
updateViewConstraints: View controller's view Start updating AutoLayout constraint .
viewWillLayoutSubviews: View controller's view Where the content view will be updated .
viewDidLayoutSubviews: View controller's view The location of the view has been updated .
viewDidAppear: View controller's view It has been shown that window On . 
viewWillDisappear: View controller's view Will be from window Go up and disappear .
viewDidDisappear: View controller's view Has gone from window Go up and disappear .


APP Life cycle of

1Not running Not running :app Not started or forced to stop .

2Inactive not active : The current application is running in the foreground , But do not receive events ( Other code may be currently executing ). Generally, whenever an application needs to switch from one state to another , The transition will stop here for a short time . The only case where you stay in this state for a long time is : When the user locks the screen , Or the system prompts the user to respond to some ( Such as telephone calls 、 There are unread messages, etc ) At the time of the event .

3Active Activate : The current application is running in the foreground , And receive events . This is the normal state when the application is running in the foreground .

4Backgroud backstage : The program is in the background and can execute code , Most programs will stay in this state for a while after entering this state . When the time expires, it will enter the suspended state (Suspended). After a special request, you can stay in Backgroud state .

5Suspended Hang up : The program cannot execute code in the background . The system will automatically change the program to this state without notification . When suspended , The program still stays in memory , When system memory is low , The system clears the pending program , Provide more memory for foreground programs 

iOS Interview questions :Autorelease Principle ?

ARC below , We use @autoreleasepool{
    } To use a Autoreleasepool, actually UIKit  adopt RunLoopObserver   stay RunLoop  secondary Sleep  between Autoreleasepool  Conduct Pop  and Push , This time Loop Produced autorelease  Object release   The compiler will compile roughly as follows :
void *DragonLiContext = objc_ AutoreleasepoolPush();
// {}  Of  code 
objc_ AutoreleasepoolPop(DragonLiContext);

Delegate and Notification The difference between ?

 It's not what the Internet says , Simple one-to-one and one to many . Because in the open source library XMPPFramework  One is provided in GCDMulticastDelegate  class , Using it, you can add multiple delegated objects to an object , that Delegate  It can also be one to many . The essential difference is actually using Delegate  when , You will tell the client what to do , When he is finished, you can tell him what to do next , This is an imperative , You need to face the client , Know who he is ; But in the use of Notification when , You just need to tell him what you want , He made it , This is a responsive , And you don't need to know who he is .

Object's copy And mutableCopy?

[immutableObject copy] //  Shallow copy  
[immutableObject mutableCopy] // Deep copy  
[mutableObject copy] // Deep copy  **** Be careful :mutableObject Use copy It's all deep copy ***
[mutableObject mutableCopy] // Deep copy  
PS: Only immutable objects copy Is a shallow copy , The rest are deep copies  ( whether kai)

GPUImage Basic concepts

GPUImage  It uses a chain method to process the picture , adopt addTarget  Method to add an object to the chain .GPUImage  Processing link  source ( video 、 Picture source )-> filter ( Filter )-> final target ( Processed video 、 picture )

Cocoapods Conflict resolution ?

  Scheme 1 、 modify podspec Inside dependencies Value of field , It can be modified if necessary platforms,source,source_files,vendored_frameworks,vendored_libraries And so on to avoid conflicts with other three-party libraries .
  Option two 、fork Source code to your own github Account number , Then change the code , When introducing  pod Keep up git Link to your own warehouse 

How to monitor memory leaks ?

 You can use the system Leaks monitoring 、 The three parties framework (MLeaksFinder) To monitor 、 perhaps dealloc To monitor VC Is it destroyed 、 perhaps Facebook Open source tools for FBRetainCycleDetecto、FBAllocationTracker、FBMemoryProfiler

Optimization method of sliding Caton of table view ?

1、 Load network pictures using asynchronous loading , And cache ; Try not to set rounded corners , Use pictures with rounded corners ;
2、cell The layout filling operation of is time-consuming , Generally, it takes a long time to create and the layout is good ;
3、 Calculate ahead of time cell And cache cell Properties of ;
4、 Try to make cell The layout is roughly the same , Different styles cell Use different reuse identifiers , Initialize add control , If it is not applicable, hide it first ;
5、 Local updates can be used cell The content of ;
6、 Because rendering takes a long time , Try to use color settings ;
7、 Customize cell, Pre arranged cell The child views ;
8、 Implement some necessary proxy methods ;
9、 In the realization of drawRect: When , its rect Parameter is the area to be drawn , There's no need to draw outside this area . For example, you can use CGRectIntersectsRect、CGRectIntersection or CGRectContainsRect Decide if you need to draw image and text, Then call the drawing method .
10、 stay bitmap context Let's draw it first , Export to UIImage object , And then draw it to the screen .

iOS Unit test framework

XCTest、GHUnit、OCMock

For code NSString*nc= [[NSArray alloc] init]; Compile time types and runtime types ?

 Compile time is NSString type , Runtime is NSArray type 

iOS There are several navigation design patterns ?

  Tile navigation ( UITabbarController )  Tag navigation ( UINavigationController )   Tree navigation (UIPageViewController)

iOS In general, there are several programs for multithreading ?

NSThread, GCD, NSOperation、Pthread

iOS The difference between multithreading schemes ?
 Please add a picture description

iOS How to avoid deadlock ?

 We can use NSRecursiveLock perhaps @synchronized replace NSLock
 because NSRecursiveLock perhaps @synchronized Are recursive locks ,
 Recursive lock : It allows the same thread to lock multiple times , Without causing a deadlock .

git rebase and git merge The difference between

 Please add a picture description
You are in a feature Branch to develop new features , meanwhile ,master Branches also have new submissions .
At this time to use merge Pictured :
 Please add a picture description
Use rebase( Variable base )
 Please add a picture description

pod install and pod update difference

Blog before Xiaobian

Multiple network requests ABC Execute... After execution D, How to design a project ?

1、 Asynchronous concurrency ( Synchronization task )
The first one is GCD group

    dispatch_group_t group = dispatch_group_create();
    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
    dispatch_group_async(group, queue, ^{
    
        NSLog(@" Synchronization task A");
    });
    
    dispatch_group_async(group, queue, ^{
    
        NSLog(@" Synchronization task B");
    });
    
    dispatch_group_async(group, queue, ^{
    
        NSLog(@" Synchronization task C");
    });
    
    dispatch_group_notify(group, queue, ^{
    
        NSLog(@" The task is completed and executed ");
    });
// 2018-04-18 10:18:52.950271+0800 GCD[2283:78081]  Synchronization task B
// 2018-04-18 10:18:52.950271+0800 GCD[2283:78082]  Synchronization task C
// 2018-04-18 10:18:52.950273+0800 GCD[2283:78083]  Synchronization task A
// 2018-04-18 10:18:52.950424+0800 GCD[2283:78082]  The task is completed and executed 
    
// 2018-04-18 10:19:30.821003+0800 GCD[2315:79354]  Synchronization task B
// 2018-04-18 10:19:30.821003+0800 GCD[2315:79355]  Synchronization task A
// 2018-04-18 10:19:30.821003+0800 GCD[2315:79370]  Synchronization task C
// 2018-04-18 10:19:30.821145+0800 GCD[2315:79355]  The task is completed and executed 

The second kind dispatch_barrier_async

dispatch_queue_t queue = dispatch_queue_create(0, DISPATCH_QUEUE_CONCURRENT);
    dispatch_async(queue, ^{
    
        NSLog(@" Mission A");
    });
    
    dispatch_async(queue, ^{
    
        NSLog(@" Mission B");
    });
    
    dispatch_async(queue, ^{
    
        NSLog(@" Mission C");
    });
    
    dispatch_barrier_async(queue, ^{
    
        NSLog(@" Block custom concurrent queues ");
    });
    
    dispatch_async(queue, ^{
    
        NSLog(@" Mission D");
    });
    
    dispatch_async(queue, ^{
    
        NSLog(@" Mission E");
    });


Create a concurrent queue by yourself , And then execute barrier function , front ABC Three tasks are random , Back DE Random , however DE The execution of must be waiting ABC The task is finished
The third kind of NSOperation

NSBlockOperation *operatioon1 = [NSBlockOperation blockOperationWithBlock:^{
    
        NSLog(@" Mission A");
    }];
    
    NSBlockOperation *operatioon2 = [NSBlockOperation blockOperationWithBlock:^{
    
        NSLog(@" Mission B");
    }];
    
    NSBlockOperation *operatioon3 = [NSBlockOperation blockOperationWithBlock:^{
    
        NSLog(@" Mission C");
    }];
    
    NSBlockOperation *operatioon4 = [NSBlockOperation blockOperationWithBlock:^{
    
        NSLog(@" Mission D");
    }];
    
    [operatioon4 addDependency:operatioon1];
    [operatioon4 addDependency:operatioon2];
    [operatioon4 addDependency:operatioon3];
    
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue addOperations:@[operatioon1,operatioon2,operatioon3,operatioon4] waitUntilFinished:YES];
    NSLog(@" Actions after completion ");

Execute through the dependencies between tasks , Last parameter YES It will block the current thread , Execute later after execution ,NO If so, it will not block .

iOS Why not use card for a long time ?

iOS Memory recovery mechanism 

IOS Use reference counting algorithm to reclaim memory , When the object reference count is 0 when , Object will execute the de initialization method and be recycled . If two objects refer to each other , It will cause circular strong reference , Cause memory leaks .

Code specification :
 Insert picture description here

ask ?

iOS The future direction of development ?

原网站

版权声明
本文为[Minjiang Xiaozhang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160032415638.html