Today to interview at a big company, more than half of your resume, however did not answer, wasted such a good chance, no heart too, very unfortunately, the record of the questions in the interview, this part mainly from sina microblogging cattle video tutorials, recent blog writing with these relationships is very small, so to write this blog to be prepared for the interview.

LRU algorithm


YYMemoryCache uses the LRU elimination algorithm, which means that when data exceeds a certain limit, we delete data from the end of the list until it reaches the limit.

In this way, array-like functions are achieved, turning unordered dictionaries into ordered collections

The caching mechanism in YYCache is different from that in SDWebImage and AFNetWorking

SDWebImage cache processing is seven days

1. Clear the exceeded maximum cache time. 2. After clearing, if the maximum cache is set, keep the previous files and delete the oldest file 4 first. Delete the oldest file to reach half of its maximum cacheCopy the code

AFNetWorking cache processing scheme:

/ / memoryCapacity memory: 100 – > 102 (100-100 = 0) / / preferredMemoryUsageAfterPurge: 60, 102-60 = 42 only need to clean up 42 according to time

dispatch_barrier_async(self.synchronizationQueue, ^{ if (self.currentMemoryUsage > self.memoryCapacity) { UInt64 bytesToPurge = self.currentMemoryUsage - self.preferredMemoryUsageAfterPurge; // 102-60=42 NSMutableArray <AFCachedImage*> *sortedImages = [NSMutableArray arrayWithArray:self.cachedImages.allValues]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastAccessDate" ascending:YES]; [sortedImages sortUsingDescriptors:@[sortDescriptor]]; UInt64 bytesPurged = 0; // Not necessarily =42, >=42, maybe the last image is bigger, For (AFCachedImage *cachedImage in sortedImages) {[self.cachedimages removeObjectForKey:cachedImage.identifier]; bytesPurged += cachedImage.totalBytes; if (bytesPurged >= bytesToPurge) { break ; } } self.currentMemoryUsage -= bytesPurged; }});Copy the code

How does TCP ensure reliable transmission?


Arrive in sequence without error or repetition

4. No errors: not lost: not repeated:Copy the code

Reliable transmission is achieved through the stop-wait protocol:

The client sends a packet M1 to the confirming client. The server sends an M2 packet to the confirming client. The server then confirms the M2 packet to the clientCopy the code

Timeout retransmission

At this point, if M1 is not sent, by default, the server does not receive the packet within a certain period of time due to the network. Therefore, the client does not acknowledge the packet and retransmits it to the serverCopy the code

** Confirm missing **

The client sends the M1 packet. The server confirms that the packet is lost. The client resends the M1 packet due to timeoutCopy the code

** Confirm late **

The client sends an M1 packet. The server sends an M1 packet late. The client retransmits the M1 packet after the server receives m1 packetsCopy the code

Sequential arrival: is achieved by sliding the window

Which network layer is HTTPS on?


HTTPS is the application layer, TCP and UDP are the transport layerCopy the code

What’s the difference between HTTPS and HTTP?


HTTPS = HTTP + SSL, the process can consult AFN source code parsing | on the first day The flow chart of directory HTTPS and explanation

The HTTP 2.0


Http1. x has keep-alive, and multiple requests within time do not need to reconnect

The following contents of the original link: blog.csdn.net/qq_36807862…

But what pain point of long connection multiplexing in HTTP1.x does HTTP2.0’s multiplexing address? HTTP/1.* Once request-response, establish a connection, close when used up; Each request establishes a connection; HTTP/1.1 Pipeling (Pipeling) is a multi-threaded process that queues up multiple requests to perform any of the following operations at any time.

That is, HTTP1.1, while reducing the consumption of TCP connections, still executes serially. HTTP2.0 Allows multiple requests to be executed concurrently on a single connection. A request task is time-consuming and does not affect the normal execution of other connections. The key to HTTP performance optimization is not high bandwidth, but low latency. TCP connections “tune” themselves over time, limiting the maximum speed of the connection at first and increasing the speed of the transfer over time if the data is successfully transferred. This tuning is called TCP slow start. For this reason, HTTP connections that are inherently abrupt and short become very inefficient. HTTP/2 enables more efficient use of TCP connections by having all data flows share the same connection, allowing high bandwidth to truly serve HTTP’s performance gains.

What are the attributes keywords


Assign, copy, strong, readwrite, made no mention of readwrite (instance variables, and attribute = instance variable + get/set), the default atomic, atomicity, statement should write noatomic.

Difficulties encountered in the project:


Here is a secret

Static and dynamic repositories:


Static library: when linking, it will be copied to the executable file completely, and there will be multiple copies when it is used for many times. Dynamic library: when linking, it will not be copied. When the program is running, it will be dynamically loaded into the memory by the system.

System library is a dynamic library, shared memory, their best use static library, will not share memory, ensure data security as for how to create a library, there is no need to explain

The main functions of blocks:


Int a= __cself->a; int a= __cself->a; copy

runtime:


What does it do:

Change the variable value exchange method to add a method to the class extension propertiesCopy the code

Change variable value:

object_setIvar(self.person, var, @”daming”); //object_setIvar(class name, attribute name, changed name)

The remaining three specific reference: www.jianshu.com/p/6bcff1f9f…

What is the difference between the structure of class method and instance method, the flow of message transfer mechanism (forget this is message passing, just know objc_msgSend)


Objc_object —- The root metaclass object, which has the id type in the OC corresponding to the objc_object class method

The objc_object contains the following: ISA_t Related to ISA operations related to weak references related to associated objects related to memory management

Is objc_class an object? A: It is an object, it has a proper name class object, class object is it!

The objc_class contains the following:

Class_data_bits_t bits, a Class variable, a property, a method, that’s all there

Existing instance method

On message transmission mechanism reference iOS | OC method in the runtime of the underlying invocation process

List inversion?

This part examines the algorithm, code address:

Github.com/tanghaitao/…

Responsibility chain, bridge, adapter, singleton, command pattern in design pattern,KVO essence

Design pattern code address:

Github.com/tanghaitao/…

Chain of responsibility


The existing services are A, B, and C. When the program starts, call A, call B, and finally call C. If the service changes one day, call C, call B, call A, how do YOU solve the problem? Businessobject. h #import <Foundation/ foundation.h > @class BusinessObject; // a b c typedef void(^CompletionBlock)(BOOL handled); Typedef void(^ResultBlock)(BusinessObject *handler, BOOL handled); // The business end handler argument 2 indicates whether the business is processed. @interface BusinessObject: NSObject // The next responder defines a member variable of the same type as the current class, forming the basic responsibility chain structure @Property (nonatomic, strong) BusinessObject *nextBusiness; // Response chain entry function - (void)handle (ResultBlock)result; // use block - (void)handleBusiness:(CompletionBlock)completion; M #import "businessobject. h" @implementation BusinessObject (void)handle: ResultBlock result {CompletionBlock completion = ^(BOOL handled){ If (handled) {result(self, handled); } else{// Not processed // along the chain of responsibility, assigned to the next business process, If (self.nextBusiness) {[self.nextBusiness handle:result]; } else{result(nil, NO);} else{result(nil, NO);} else{result(nil, NO); }}}; / / the current business process, there is different business. A, b, c, equivalent to the current object of different classes, different business processes, such as a business process is completed is called the block code above [self handleBusiness: completion]. } - (void)handleBusiness:(CompletionBlock)completion {/* handleBusiness logic such as network requests, local photo queries, etc. To solve this problem using the chain of responsibility pattern, business C can be the first to deal with, and have its nextBusiness point to B, which can have its nextBusiness point to C, and which can have C's nextBusiness point to nilCopy the code

The bridge

11-3 Bridging mode related interview questions

Interview question: How do you understand bridging?

A question related to business decoupling:

A VC list, which changes from network data B1 to network data B2 and then to network data B3, has three changes in the network data in the same list, but these three sets of data need to coexist, for example, to judge which set of data should be used at this time, for this demand, this design scheme and thinking?

The coupling problem between lists and data can be solved by bridging patterns.

Class composition of the bridge pattern:

For example, if there is an abstract class A and one of the member variables is abstract class B, the key abstract class A that forms the bridge pattern has three subclasses A1, A2,a3, and abstract class B has three subclasses B1, B2,b3, the VC list can be regarded as the subclass A2 of abstract class A, and the three sets of lists can be regarded as B1, B2,b3, to solve the above problem

BaseObjectA is the abstract class a ObjectA1, and ObjectA2 is the subclass of BaseObjectB. ObjectB2 is a subclass of BaseObjectB. ObjectA1 can use ObjectB1 and ObjectB2 data. ObjectA2 can use ObjectB1 and ObjectB2 dataCopy the code

audi