You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1 KiB

  1. //
  2. // Kingfisher.swift
  3. // Kingfisher
  4. //
  5. // Created by Wei Wang on 16/9/14.
  6. //
  7. // Copyright (c) 2019 Wei Wang <onevcat@gmail.com>
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. import Foundation
  27. import ImageIO
  28. #if os(macOS)
  29. import AppKit
  30. public typealias KFCrossPlatformImage = NSImage
  31. public typealias KFCrossPlatformView = NSView
  32. public typealias KFCrossPlatformColor = NSColor
  33. public typealias KFCrossPlatformImageView = NSImageView
  34. public typealias KFCrossPlatformButton = NSButton
  35. #else
  36. import UIKit
  37. public typealias KFCrossPlatformImage = UIImage
  38. public typealias KFCrossPlatformColor = UIColor
  39. #if !os(watchOS)
  40. public typealias KFCrossPlatformImageView = UIImageView
  41. public typealias KFCrossPlatformView = UIView
  42. public typealias KFCrossPlatformButton = UIButton
  43. #else
  44. import WatchKit
  45. #endif
  46. #endif
  47. /// Wrapper for Kingfisher compatible types. This type provides an extension point for
  48. /// connivence methods in Kingfisher.
  49. public struct KingfisherWrapper<Base> {
  50. public let base: Base
  51. public init(_ base: Base) {
  52. self.base = base
  53. }
  54. }
  55. /// Represents an object type that is compatible with Kingfisher. You can use `kf` property to get a
  56. /// value in the namespace of Kingfisher.
  57. public protocol KingfisherCompatible: AnyObject { }
  58. /// Represents a value type that is compatible with Kingfisher. You can use `kf` property to get a
  59. /// value in the namespace of Kingfisher.
  60. public protocol KingfisherCompatibleValue {}
  61. extension KingfisherCompatible {
  62. /// Gets a namespace holder for Kingfisher compatible types.
  63. public var kf: KingfisherWrapper<Self> {
  64. get { return KingfisherWrapper(self) }
  65. set { }
  66. }
  67. }
  68. extension KingfisherCompatibleValue {
  69. /// Gets a namespace holder for Kingfisher compatible types.
  70. public var kf: KingfisherWrapper<Self> {
  71. get { return KingfisherWrapper(self) }
  72. set { }
  73. }
  74. }
  75. extension KFCrossPlatformImage: KingfisherCompatible { }
  76. #if !os(watchOS)
  77. extension KFCrossPlatformImageView: KingfisherCompatible { }
  78. extension KFCrossPlatformButton: KingfisherCompatible { }
  79. #else
  80. extension WKInterfaceImage: KingfisherCompatible { }
  81. #endif