1. Use of namespaces

Kingfisher namespaces can be used in two ways, either by using a protocol plus wrapper, or by defining a type in an enumeration. KingfisherCompatible public enum MemoryStorage {}, an empty protocol that extends a kf calculation property but has a base pointing to it, and an empty enumeration that defines a type with its own namespace. The second is used in Alamofire5.0

2. Understanding enumeration

Kingfisher uses a lot of enumerations. I used to think that enumerations were meant to distinguish states and improve code readability, but now it’s understood that enumerations define a set of values that have the same meaning but may have different behavior policies. Such as KingfisherOptionsInfoItem defines the various configurations of Kingfisher, but the meaning of each configuration may be completely different, but are configured, ExpirationExtending defines how to update the expiration time again,

3. The important role of protocols in improving scalability

Protocol defines certain capabilities, which are realized by protocol adherents. However, due to the existence of protocol extension in Swift, the protocol itself can provide certain capabilities. As long as the protocol adherents follow the protocol, they can automatically obtain these capabilities, reducing the complexity of protocol compliance. And the protocol only defines certain capabilities, not specific types, more aspects to extend. My favorite protocols are Resource, Placeholder,Processor

4. Use of OptionSet

OptionSet is similar to a bitwise enumeration of OC. OptionSet follows RawRepresentable, which requires that a rawValue be provided. OptionSet also follows SetAlgebra, which is a very convenient array literal for assignment. Public static let all: RectCorner = [. TopLeft,. TopRight,. BottomLeft,. BottomRight

5. Load the loading of the hd large image

In order to reduce the loading of memory, we can use down sampling to load the hd large image. This is also the way to show the HD image in Kingfisher’s demo. One drawback of this method is that if we need to show the HD image in a method, it may become fuzzy. CATiledLayer can be used to display the hd map, which can be segmented

6. 2 ways to load giFs

  1. Get all the images from the GIF and use uiImage.animateImage () to generate a GIF and assign it to UIImageView
  2. Custom ImageView inherits from UIImageView and implements a timer to display the corresponding frame of GIF image according to the corresponding time

7. Judge the principle of picture format

General picture format are in the first few bytes of data, as long as the corresponding rules to take, and then determine the line

8. Decode the image in the child thread

Decoding an image in a child thread is drawing the UIImage onto a canvas in the child thread, and pulling the image from the canvas

9. Defer’s help to improve code brevity

As you can see from the picture below, the context created 2. This needs to be released twice and can only be released after painting. What would you say if you did not defer

10. Kingfisher is such a simple way to use, but there are a lot of smart Settings

This is because there is a default value for each configuration item or a default treatment for a configuration item that is nil. When we configure options, Options is of type public typealias KingfisherOptionsInfo = [KingfisherOptionsInfoItem], and use it every time you feel you really in Kingfisher is structure KingfisherParsedOptionsInfo, due to the configuration items too many attributes, direct use of structure, initialized structure of time is not convenient, and use an array, Generated by traversal KingfisherParsedOptionsInfo again, will be more convenient, for the detail processing of meow god thumb up