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.

654 lines
28 KiB

  1. //
  2. // Deprecated.swift
  3. // Kingfisher
  4. //
  5. // Created by onevcat on 2018/09/28.
  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. #if canImport(AppKit)
  27. import AppKit
  28. #elseif canImport(UIKit)
  29. import UIKit
  30. #endif
  31. // MARK: - Deprecated
  32. extension KingfisherWrapper where Base: Image {
  33. @available(*, deprecated, message:
  34. "Will be removed soon. Pass parameters with `ImageCreatingOptions`, use `image(with:options:)` instead.")
  35. public static func image(
  36. data: Data,
  37. scale: CGFloat,
  38. preloadAllAnimationData: Bool,
  39. onlyFirstFrame: Bool) -> Image?
  40. {
  41. let options = ImageCreatingOptions(
  42. scale: scale,
  43. duration: 0.0,
  44. preloadAll: preloadAllAnimationData,
  45. onlyFirstFrame: onlyFirstFrame)
  46. return KingfisherWrapper.image(data: data, options: options)
  47. }
  48. @available(*, deprecated, message:
  49. "Will be removed soon. Pass parameters with `ImageCreatingOptions`, use `animatedImage(with:options:)` instead.")
  50. public static func animated(
  51. with data: Data,
  52. scale: CGFloat = 1.0,
  53. duration: TimeInterval = 0.0,
  54. preloadAll: Bool,
  55. onlyFirstFrame: Bool = false) -> Image?
  56. {
  57. let options = ImageCreatingOptions(
  58. scale: scale, duration: duration, preloadAll: preloadAll, onlyFirstFrame: onlyFirstFrame)
  59. return animatedImage(data: data, options: options)
  60. }
  61. }
  62. @available(*, deprecated, message: "Will be removed soon. Use `Result<RetrieveImageResult>` based callback instead")
  63. public typealias CompletionHandler =
  64. ((_ image: Image?, _ error: NSError?, _ cacheType: CacheType, _ imageURL: URL?) -> Void)
  65. @available(*, deprecated, message: "Will be removed soon. Use `Result<ImageLoadingResult>` based callback instead")
  66. public typealias ImageDownloaderCompletionHandler =
  67. ((_ image: Image?, _ error: NSError?, _ url: URL?, _ originalData: Data?) -> Void)
  68. // MARK: - Deprecated
  69. @available(*, deprecated, message: "Will be removed soon. Use `DownloadTask` to cancel a task.")
  70. extension RetrieveImageTask {
  71. @available(*, deprecated, message: "RetrieveImageTask.empty will be removed soon. Use `nil` to represent a no task.")
  72. public static let empty = RetrieveImageTask()
  73. }
  74. // MARK: - Deprecated
  75. extension KingfisherManager {
  76. /// Get an image with resource.
  77. /// If `.empty` is used as `options`, Kingfisher will seek the image in memory and disk first.
  78. /// If not found, it will download the image at `resource.downloadURL` and cache it with `resource.cacheKey`.
  79. /// These default behaviors could be adjusted by passing different options. See `KingfisherOptions` for more.
  80. ///
  81. /// - Parameters:
  82. /// - resource: Resource object contains information such as `cacheKey` and `downloadURL`.
  83. /// - options: A dictionary could control some behaviors. See `KingfisherOptionsInfo` for more.
  84. /// - progressBlock: Called every time downloaded data changed. This could be used as a progress UI.
  85. /// - completionHandler: Called when the whole retrieving process finished.
  86. /// - Returns: A `RetrieveImageTask` task object. You can use this object to cancel the task.
  87. @available(*, deprecated, message: "Use `Result` based callback instead.")
  88. @discardableResult
  89. public func retrieveImage(with resource: Resource,
  90. options: KingfisherOptionsInfo?,
  91. progressBlock: DownloadProgressBlock?,
  92. completionHandler: CompletionHandler?) -> DownloadTask?
  93. {
  94. return retrieveImage(with: resource, options: options, progressBlock: progressBlock) {
  95. result in
  96. switch result {
  97. case .success(let value): completionHandler?(value.image, nil, value.cacheType, value.source.url)
  98. case .failure(let error): completionHandler?(nil, error as NSError, .none, resource.downloadURL)
  99. }
  100. }
  101. }
  102. }
  103. // MARK: - Deprecated
  104. extension ImageDownloader {
  105. @available(*, deprecated, message: "Use `Result` based callback instead.")
  106. @discardableResult
  107. open func downloadImage(with url: URL,
  108. retrieveImageTask: RetrieveImageTask? = nil,
  109. options: KingfisherOptionsInfo? = nil,
  110. progressBlock: ImageDownloaderProgressBlock? = nil,
  111. completionHandler: ImageDownloaderCompletionHandler?) -> DownloadTask?
  112. {
  113. return downloadImage(with: url, options: options, progressBlock: progressBlock) {
  114. result in
  115. switch result {
  116. case .success(let value): completionHandler?(value.image, nil, value.url, value.originalData)
  117. case .failure(let error): completionHandler?(nil, error as NSError, nil, nil)
  118. }
  119. }
  120. }
  121. }
  122. @available(*, deprecated, message: "RetrieveImageDownloadTask is removed. Use `DownloadTask` to cancel a task.")
  123. public struct RetrieveImageDownloadTask {
  124. }
  125. @available(*, deprecated, message: "RetrieveImageTask is removed. Use `DownloadTask` to cancel a task.")
  126. public final class RetrieveImageTask {
  127. }
  128. @available(*, deprecated, message: "Use `DownloadProgressBlock` instead.", renamed: "DownloadProgressBlock")
  129. public typealias ImageDownloaderProgressBlock = DownloadProgressBlock
  130. #if !os(watchOS)
  131. // MARK: - Deprecated
  132. extension KingfisherWrapper where Base: ImageView {
  133. @available(*, deprecated, message: "Use `Result` based callback instead.")
  134. @discardableResult
  135. public func setImage(with resource: Resource?,
  136. placeholder: Placeholder? = nil,
  137. options: KingfisherOptionsInfo? = nil,
  138. progressBlock: DownloadProgressBlock? = nil,
  139. completionHandler: CompletionHandler?) -> DownloadTask?
  140. {
  141. return setImage(with: resource, placeholder: placeholder, options: options, progressBlock: progressBlock) {
  142. result in
  143. switch result {
  144. case .success(let value):
  145. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  146. case .failure(let error):
  147. completionHandler?(nil, error as NSError, .none, nil)
  148. }
  149. }
  150. }
  151. }
  152. #endif
  153. #if canImport(UIKit) && !os(watchOS)
  154. // MARK: - Deprecated
  155. extension KingfisherWrapper where Base: UIButton {
  156. @available(*, deprecated, message: "Use `Result` based callback instead.")
  157. @discardableResult
  158. public func setImage(
  159. with resource: Resource?,
  160. for state: UIControl.State,
  161. placeholder: UIImage? = nil,
  162. options: KingfisherOptionsInfo? = nil,
  163. progressBlock: DownloadProgressBlock? = nil,
  164. completionHandler: CompletionHandler?) -> DownloadTask?
  165. {
  166. return setImage(
  167. with: resource,
  168. for: state,
  169. placeholder: placeholder,
  170. options: options,
  171. progressBlock: progressBlock)
  172. {
  173. result in
  174. switch result {
  175. case .success(let value):
  176. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  177. case .failure(let error):
  178. completionHandler?(nil, error as NSError, .none, nil)
  179. }
  180. }
  181. }
  182. @available(*, deprecated, message: "Use `Result` based callback instead.")
  183. @discardableResult
  184. public func setBackgroundImage(
  185. with resource: Resource?,
  186. for state: UIControl.State,
  187. placeholder: UIImage? = nil,
  188. options: KingfisherOptionsInfo? = nil,
  189. progressBlock: DownloadProgressBlock? = nil,
  190. completionHandler: CompletionHandler?) -> DownloadTask?
  191. {
  192. return setBackgroundImage(
  193. with: resource,
  194. for: state,
  195. placeholder: placeholder,
  196. options: options,
  197. progressBlock: progressBlock)
  198. {
  199. result in
  200. switch result {
  201. case .success(let value):
  202. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  203. case .failure(let error):
  204. completionHandler?(nil, error as NSError, .none, nil)
  205. }
  206. }
  207. }
  208. }
  209. #endif
  210. #if os(watchOS)
  211. import WatchKit
  212. // MARK: - Deprecated
  213. extension KingfisherWrapper where Base: WKInterfaceImage {
  214. @available(*, deprecated, message: "Use `Result` based callback instead.")
  215. @discardableResult
  216. public func setImage(_ resource: Resource?,
  217. placeholder: Image? = nil,
  218. options: KingfisherOptionsInfo? = nil,
  219. progressBlock: DownloadProgressBlock? = nil,
  220. completionHandler: CompletionHandler?) -> DownloadTask?
  221. {
  222. return setImage(
  223. with: resource,
  224. placeholder: placeholder,
  225. options: options,
  226. progressBlock: progressBlock)
  227. {
  228. result in
  229. switch result {
  230. case .success(let value):
  231. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  232. case .failure(let error):
  233. completionHandler?(nil, error as NSError, .none, nil)
  234. }
  235. }
  236. }
  237. }
  238. #endif
  239. #if os(macOS)
  240. // MARK: - Deprecated
  241. extension KingfisherWrapper where Base: NSButton {
  242. @discardableResult
  243. @available(*, deprecated, message: "Use `Result` based callback instead.")
  244. public func setImage(with resource: Resource?,
  245. placeholder: Image? = nil,
  246. options: KingfisherOptionsInfo? = nil,
  247. progressBlock: DownloadProgressBlock? = nil,
  248. completionHandler: CompletionHandler?) -> DownloadTask?
  249. {
  250. return setImage(
  251. with: resource,
  252. placeholder: placeholder,
  253. options: options,
  254. progressBlock: progressBlock)
  255. {
  256. result in
  257. switch result {
  258. case .success(let value):
  259. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  260. case .failure(let error):
  261. completionHandler?(nil, error as NSError, .none, nil)
  262. }
  263. }
  264. }
  265. @discardableResult
  266. @available(*, deprecated, message: "Use `Result` based callback instead.")
  267. public func setAlternateImage(with resource: Resource?,
  268. placeholder: Image? = nil,
  269. options: KingfisherOptionsInfo? = nil,
  270. progressBlock: DownloadProgressBlock? = nil,
  271. completionHandler: CompletionHandler?) -> DownloadTask?
  272. {
  273. return setAlternateImage(
  274. with: resource,
  275. placeholder: placeholder,
  276. options: options,
  277. progressBlock: progressBlock)
  278. {
  279. result in
  280. switch result {
  281. case .success(let value):
  282. completionHandler?(value.image, nil, value.cacheType, value.source.url)
  283. case .failure(let error):
  284. completionHandler?(nil, error as NSError, .none, nil)
  285. }
  286. }
  287. }
  288. }
  289. #endif
  290. // MARK: - Deprecated
  291. extension ImageCache {
  292. /// The largest cache cost of memory cache. The total cost is pixel count of
  293. /// all cached images in memory.
  294. /// Default is unlimited. Memory cache will be purged automatically when a
  295. /// memory warning notification is received.
  296. @available(*, deprecated, message: "Use `memoryStorage.config.totalCostLimit` instead.",
  297. renamed: "memoryStorage.config.totalCostLimit")
  298. open var maxMemoryCost: Int {
  299. get { return memoryStorage.config.totalCostLimit }
  300. set { memoryStorage.config.totalCostLimit = newValue }
  301. }
  302. /// The default DiskCachePathClosure
  303. @available(*, deprecated, message: "Not needed anymore.")
  304. public final class func defaultDiskCachePathClosure(path: String?, cacheName: String) -> String {
  305. let dstPath = path ?? NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!
  306. return (dstPath as NSString).appendingPathComponent(cacheName)
  307. }
  308. /// The default file extension appended to cached files.
  309. @available(*, deprecated, message: "Use `diskStorage.config.pathExtension` instead.",
  310. renamed: "diskStorage.config.pathExtension")
  311. open var pathExtension: String? {
  312. get { return diskStorage.config.pathExtension }
  313. set { diskStorage.config.pathExtension = newValue }
  314. }
  315. ///The disk cache location.
  316. @available(*, deprecated, message: "Use `diskStorage.directoryURL.absoluteString` instead.",
  317. renamed: "diskStorage.directoryURL.absoluteString")
  318. public var diskCachePath: String {
  319. return diskStorage.directoryURL.absoluteString
  320. }
  321. /// The largest disk size can be taken for the cache. It is the total
  322. /// allocated size of cached files in bytes.
  323. /// Default is no limit.
  324. @available(*, deprecated, message: "Use `diskStorage.config.sizeLimit` instead.",
  325. renamed: "diskStorage.config.sizeLimit")
  326. open var maxDiskCacheSize: UInt {
  327. get { return UInt(diskStorage.config.sizeLimit) }
  328. set { diskStorage.config.sizeLimit = newValue }
  329. }
  330. @available(*, deprecated, message: "Use `diskStorage.cacheFileURL(forKey:).path` instead.",
  331. renamed: "diskStorage.cacheFileURL(forKey:)")
  332. open func cachePath(forComputedKey key: String) -> String {
  333. return diskStorage.cacheFileURL(forKey: key).path
  334. }
  335. /**
  336. Get an image for a key from disk.
  337. - parameter key: Key for the image.
  338. - parameter options: Options of retrieving image. If you need to retrieve an image which was
  339. stored with a specified `ImageProcessor`, pass the processor in the option too.
  340. - returns: The image object if it is cached, or `nil` if there is no such key in the cache.
  341. */
  342. @available(*, deprecated,
  343. message: "Use `Result` based `retrieveImageInDiskCache(forKey:options:callbackQueue:completionHandler:)` instead.",
  344. renamed: "retrieveImageInDiskCache(forKey:options:callbackQueue:completionHandler:)")
  345. open func retrieveImageInDiskCache(forKey key: String, options: KingfisherOptionsInfo? = nil) -> Image? {
  346. let options = options ?? .empty
  347. let computedKey = key.computedKey(with: options.processor.identifier)
  348. do {
  349. if let data = try diskStorage.value(forKey: computedKey) {
  350. return options.cacheSerializer.image(with: data, options: options)
  351. }
  352. } catch {}
  353. return nil
  354. }
  355. @available(*, deprecated,
  356. message: "Use `Result` based `retrieveImage(forKey:options:callbackQueue:completionHandler:)` instead.",
  357. renamed: "retrieveImage(forKey:options:callbackQueue:completionHandler:)")
  358. open func retrieveImage(forKey key: String,
  359. options: KingfisherOptionsInfo?,
  360. completionHandler: ((Image?, CacheType) -> Void)?)
  361. {
  362. retrieveImage(
  363. forKey: key,
  364. options: options,
  365. callbackQueue: .dispatch((options ?? .empty).callbackDispatchQueue))
  366. {
  367. result in
  368. do {
  369. let value = try result.get()
  370. completionHandler?(value.image, value.cacheType)
  371. } catch {
  372. completionHandler?(nil, .none)
  373. }
  374. }
  375. }
  376. /// The longest time duration in second of the cache being stored in disk.
  377. /// Default is 1 week (60 * 60 * 24 * 7 seconds).
  378. /// Setting this to a negative value will make the disk cache never expiring.
  379. @available(*, deprecated, message: "Deprecated. Use `diskStorage.config.expiration` instead")
  380. open var maxCachePeriodInSecond: TimeInterval {
  381. get { return diskStorage.config.expiration.timeInterval }
  382. set { diskStorage.config.expiration = newValue < 0 ? .never : .seconds(newValue) }
  383. }
  384. @available(*, deprecated, message: "Use `Result` based callback instead.")
  385. open func store(_ image: Image,
  386. original: Data? = nil,
  387. forKey key: String,
  388. processorIdentifier identifier: String = "",
  389. cacheSerializer serializer: CacheSerializer = DefaultCacheSerializer.default,
  390. toDisk: Bool = true,
  391. completionHandler: (() -> Void)?)
  392. {
  393. store(
  394. image,
  395. original: original,
  396. forKey: key,
  397. processorIdentifier: identifier,
  398. cacheSerializer: serializer,
  399. toDisk: toDisk)
  400. {
  401. _ in
  402. completionHandler?()
  403. }
  404. }
  405. @available(*, deprecated, message: "Use the `Result`-based `calculateDiskStorageSize` instead.")
  406. open func calculateDiskCacheSize(completion handler: @escaping ((_ size: UInt) -> Void)) {
  407. calculateDiskStorageSize { result in
  408. let size: UInt? = try? result.get()
  409. handler(size ?? 0)
  410. }
  411. }
  412. }
  413. // MARK: - Deprecated
  414. extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
  415. /// The queue of callbacks should happen from Kingfisher.
  416. @available(*, deprecated, message: "Use `callbackQueue` instead.", renamed: "callbackQueue")
  417. public var callbackDispatchQueue: DispatchQueue {
  418. return KingfisherParsedOptionsInfo(Array(self)).callbackQueue.queue
  419. }
  420. }
  421. /// Error domain of Kingfisher
  422. @available(*, deprecated, message: "Use `KingfisherError.domain` instead.", renamed: "KingfisherError.domain")
  423. public let KingfisherErrorDomain = "com.onevcat.Kingfisher.Error"
  424. /// Key will be used in the `userInfo` of `.invalidStatusCode`
  425. @available(*, unavailable,
  426. message: "Use `.invalidHTTPStatusCode` or `isInvalidResponseStatusCode` of `KingfisherError` instead for the status code.")
  427. public let KingfisherErrorStatusCodeKey = "statusCode"
  428. // MARK: - Deprecated
  429. extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
  430. /// The target `ImageCache` which is used.
  431. @available(*, deprecated,
  432. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `targetCache` instead.")
  433. public var targetCache: ImageCache? {
  434. return KingfisherParsedOptionsInfo(Array(self)).targetCache
  435. }
  436. /// The original `ImageCache` which is used.
  437. @available(*, deprecated,
  438. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `originalCache` instead.")
  439. public var originalCache: ImageCache? {
  440. return KingfisherParsedOptionsInfo(Array(self)).originalCache
  441. }
  442. /// The `ImageDownloader` which is specified.
  443. @available(*, deprecated,
  444. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `downloader` instead.")
  445. public var downloader: ImageDownloader? {
  446. return KingfisherParsedOptionsInfo(Array(self)).downloader
  447. }
  448. /// Member for animation transition when using UIImageView.
  449. @available(*, deprecated,
  450. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `transition` instead.")
  451. public var transition: ImageTransition {
  452. return KingfisherParsedOptionsInfo(Array(self)).transition
  453. }
  454. /// A `Float` value set as the priority of image download task. The value for it should be
  455. /// between 0.0~1.0.
  456. @available(*, deprecated,
  457. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `downloadPriority` instead.")
  458. public var downloadPriority: Float {
  459. return KingfisherParsedOptionsInfo(Array(self)).downloadPriority
  460. }
  461. /// Whether an image will be always downloaded again or not.
  462. @available(*, deprecated,
  463. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `forceRefresh` instead.")
  464. public var forceRefresh: Bool {
  465. return KingfisherParsedOptionsInfo(Array(self)).forceRefresh
  466. }
  467. /// Whether an image should be got only from memory cache or download.
  468. @available(*, deprecated,
  469. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `fromMemoryCacheOrRefresh` instead.")
  470. public var fromMemoryCacheOrRefresh: Bool {
  471. return KingfisherParsedOptionsInfo(Array(self)).fromMemoryCacheOrRefresh
  472. }
  473. /// Whether the transition should always happen or not.
  474. @available(*, deprecated,
  475. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `forceTransition` instead.")
  476. public var forceTransition: Bool {
  477. return KingfisherParsedOptionsInfo(Array(self)).forceTransition
  478. }
  479. /// Whether cache the image only in memory or not.
  480. @available(*, deprecated,
  481. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `cacheMemoryOnly` instead.")
  482. public var cacheMemoryOnly: Bool {
  483. return KingfisherParsedOptionsInfo(Array(self)).cacheMemoryOnly
  484. }
  485. /// Whether the caching operation will be waited or not.
  486. @available(*, deprecated,
  487. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `waitForCache` instead.")
  488. public var waitForCache: Bool {
  489. return KingfisherParsedOptionsInfo(Array(self)).waitForCache
  490. }
  491. /// Whether only load the images from cache or not.
  492. @available(*, deprecated,
  493. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `onlyFromCache` instead.")
  494. public var onlyFromCache: Bool {
  495. return KingfisherParsedOptionsInfo(Array(self)).onlyFromCache
  496. }
  497. /// Whether the image should be decoded in background or not.
  498. @available(*, deprecated,
  499. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `backgroundDecode` instead.")
  500. public var backgroundDecode: Bool {
  501. return KingfisherParsedOptionsInfo(Array(self)).backgroundDecode
  502. }
  503. /// Whether the image data should be all loaded at once if it is an animated image.
  504. @available(*, deprecated,
  505. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `preloadAllAnimationData` instead.")
  506. public var preloadAllAnimationData: Bool {
  507. return KingfisherParsedOptionsInfo(Array(self)).preloadAllAnimationData
  508. }
  509. /// The `CallbackQueue` on which completion handler should be invoked.
  510. /// If not set in the options, `.mainCurrentOrAsync` will be used.
  511. @available(*, deprecated,
  512. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `callbackQueue` instead.")
  513. public var callbackQueue: CallbackQueue {
  514. return KingfisherParsedOptionsInfo(Array(self)).callbackQueue
  515. }
  516. /// The scale factor which should be used for the image.
  517. @available(*, deprecated,
  518. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `scaleFactor` instead.")
  519. public var scaleFactor: CGFloat {
  520. return KingfisherParsedOptionsInfo(Array(self)).scaleFactor
  521. }
  522. /// The `ImageDownloadRequestModifier` will be used before sending a download request.
  523. @available(*, deprecated,
  524. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `requestModifier` instead.")
  525. public var modifier: ImageDownloadRequestModifier? {
  526. return KingfisherParsedOptionsInfo(Array(self)).requestModifier
  527. }
  528. /// `ImageProcessor` for processing when the downloading finishes.
  529. @available(*, deprecated,
  530. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `processor` instead.")
  531. public var processor: ImageProcessor {
  532. return KingfisherParsedOptionsInfo(Array(self)).processor
  533. }
  534. /// `ImageModifier` for modifying right before the image is displayed.
  535. @available(*, deprecated,
  536. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `imageModifier` instead.")
  537. public var imageModifier: ImageModifier? {
  538. return KingfisherParsedOptionsInfo(Array(self)).imageModifier
  539. }
  540. /// `CacheSerializer` to convert image to data for storing in cache.
  541. @available(*, deprecated,
  542. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `cacheSerializer` instead.")
  543. public var cacheSerializer: CacheSerializer {
  544. return KingfisherParsedOptionsInfo(Array(self)).cacheSerializer
  545. }
  546. /// Keep the existing image while setting another image to an image view.
  547. /// Or the placeholder will be used while downloading.
  548. @available(*, deprecated,
  549. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `keepCurrentImageWhileLoading` instead.")
  550. public var keepCurrentImageWhileLoading: Bool {
  551. return KingfisherParsedOptionsInfo(Array(self)).keepCurrentImageWhileLoading
  552. }
  553. /// Whether the options contains `.onlyLoadFirstFrame`.
  554. @available(*, deprecated,
  555. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `onlyLoadFirstFrame` instead.")
  556. public var onlyLoadFirstFrame: Bool {
  557. return KingfisherParsedOptionsInfo(Array(self)).onlyLoadFirstFrame
  558. }
  559. /// Whether the options contains `.cacheOriginalImage`.
  560. @available(*, deprecated,
  561. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `cacheOriginalImage` instead.")
  562. public var cacheOriginalImage: Bool {
  563. return KingfisherParsedOptionsInfo(Array(self)).cacheOriginalImage
  564. }
  565. /// The image which should be used when download image request fails.
  566. @available(*, deprecated,
  567. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `onFailureImage` instead.")
  568. public var onFailureImage: Optional<Image?> {
  569. return KingfisherParsedOptionsInfo(Array(self)).onFailureImage
  570. }
  571. /// Whether the `ImagePrefetcher` should load images to memory in an aggressive way or not.
  572. @available(*, deprecated,
  573. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `alsoPrefetchToMemory` instead.")
  574. public var alsoPrefetchToMemory: Bool {
  575. return KingfisherParsedOptionsInfo(Array(self)).alsoPrefetchToMemory
  576. }
  577. /// Whether the disk storage file loading should happen in a synchronous behavior or not.
  578. @available(*, deprecated,
  579. message: "Create a `KingfisherParsedOptionsInfo` from `KingfisherOptionsInfo` and use `loadDiskFileSynchronously` instead.")
  580. public var loadDiskFileSynchronously: Bool {
  581. return KingfisherParsedOptionsInfo(Array(self)).loadDiskFileSynchronously
  582. }
  583. }
  584. /// The default modifier.
  585. /// It does nothing and returns the image as is.
  586. @available(*, deprecated, message: "Use `nil` in KingfisherOptionsInfo to indicate no modifier.")
  587. public struct DefaultImageModifier: ImageModifier {
  588. /// A default `DefaultImageModifier` which can be used everywhere.
  589. public static let `default` = DefaultImageModifier()
  590. private init() {}
  591. /// Modifies an input `Image`. See `ImageModifier` protocol for more.
  592. public func modify(_ image: Image) -> Image { return image }
  593. }