Deprecated.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // Deprecated.swift
  3. // Kingfisher
  4. //
  5. // Created by onevcat on 2018/09/28.
  6. //
  7. // Copyright (c) 2018 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. #if canImport(AppKit)
  27. import AppKit
  28. #elseif canImport(UIKit)
  29. import UIKit
  30. #endif
  31. extension KingfisherClass where Base: Image {
  32. @available(*, deprecated, message:
  33. "Pass parameters with `ImageCreatingOptions`, use `image(with:options:)` instead.")
  34. public static func image(
  35. data: Data,
  36. scale: CGFloat,
  37. preloadAllAnimationData: Bool,
  38. onlyFirstFrame: Bool) -> Image?
  39. {
  40. let options = ImageCreatingOptions(
  41. scale: scale,
  42. duration: 0.0,
  43. preloadAll: preloadAllAnimationData,
  44. onlyFirstFrame: onlyFirstFrame)
  45. return KingfisherClass.image(data: data, options: options)
  46. }
  47. @available(*, deprecated, message:
  48. "Pass parameters with `ImageCreatingOptions`, use `animatedImage(with:options:)` instead.")
  49. public static func animated(
  50. with data: Data,
  51. scale: CGFloat = 1.0,
  52. duration: TimeInterval = 0.0,
  53. preloadAll: Bool,
  54. onlyFirstFrame: Bool = false) -> Image?
  55. {
  56. let options = ImageCreatingOptions(
  57. scale: scale, duration: duration, preloadAll: preloadAll, onlyFirstFrame: onlyFirstFrame)
  58. return animatedImage(data: data, options: options)
  59. }
  60. }
  61. @available(*, deprecated, message: "Use `Result<ImageResult>` based callback instead")
  62. public typealias CompletionHandler = ((_ image: Image?, _ error: NSError?, _ cacheType: CacheType, _ imageURL: URL?) -> Void)
  63. extension RetrieveImageTask {
  64. @available(*, deprecated, message: "RetrieveImageTask.empty will be removed soon. Use `nil` to represnt a no task.")
  65. public static let empty = RetrieveImageTask()
  66. }
  67. extension KingfisherManager {
  68. /// Get an image with resource.
  69. /// If `.empty` is used as `options`, Kingfisher will seek the image in memory and disk first.
  70. /// If not found, it will download the image at `resource.downloadURL` and cache it with `resource.cacheKey`.
  71. /// These default behaviors could be adjusted by passing different options. See `KingfisherOptions` for more.
  72. ///
  73. /// - Parameters:
  74. /// - resource: Resource object contains information such as `cacheKey` and `downloadURL`.
  75. /// - options: A dictionary could control some behaviors. See `KingfisherOptionsInfo` for more.
  76. /// - progressBlock: Called every time downloaded data changed. This could be used as a progress UI.
  77. /// - completionHandler: Called when the whole retrieving process finished.
  78. /// - Returns: A `RetrieveImageTask` task object. You can use this object to cancel the task.
  79. @available(*, deprecated, message: "Use `Result` based callback instead.")
  80. @discardableResult
  81. public func retrieveImage(with resource: Resource,
  82. options: KingfisherOptionsInfo?,
  83. progressBlock: DownloadProgressBlock?,
  84. completionHandler: CompletionHandler?) -> RetrieveImageTask
  85. {
  86. return retrieveImage(with: resource, options: options, progressBlock: progressBlock) {
  87. result in
  88. switch result {
  89. case .success(let value): completionHandler?(value.image, nil, value.cacheType, value.imageURL)
  90. case .failure(let error): completionHandler?(nil, error as NSError, .none, nil)
  91. }
  92. }
  93. }
  94. }