<aside> 📌 목차
</aside>
.kf
네임스페이스 추가하기RxSwift 에서 .rx 라는 네임스페이스를 추가하고 그 하위에 멤버(속성, 메서드)를 넣은 것과 유사한 방법
KingFisherWrapper
/// Wrapper for Kingfisher compatible types. This type provides an extension point for
/// convenience methods in Kingfisher.
public struct KingfisherWrapper<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
KingFisherCompatible
/// Represents an object type that is compatible with Kingfisher. You can use `kf` property to get a
/// value in the namespace of Kingfisher.
public protocol KingfisherCompatible: AnyObject { }
extension KingFisherCompatible
kf
라는 속성을 추가한다.extension KingfisherCompatible {
/// Gets a namespace holder for Kingfisher compatible types.
public var kf: KingfisherWrapper<Self> {
get { return KingfisherWrapper(self) }
~~set { }~~
}
}
UIImageView
를 프로토콜에 준수시킴네이밍: 멀티플랫폼(iOS, macOS, WatchOS 등)을 고려한 코드
지시어(?) 를 통해 #if os(iOS) 인 경우 아래와 같이 정의
#if !os(watchOS)
public typealias KFCrossPlatformImageView = UIImageView
...
#endif
extension KFCrossPlatformImageView: KingfisherCompatible { }