From bcf9d2fe73f22ab6ce4cabe0ee0159100347407b Mon Sep 17 00:00:00 2001 From: Callum Trounce Date: Wed, 18 Sep 2019 22:08:11 +0100 Subject: [PATCH] some cleanup. --- .../RemoteImage/Cache/FileManager+Paths.swift | 3 --- .../RemoteImage/Cache/ImageCacheType.swift | 3 --- .../Cache/InMemoryImageCache.swift | 1 - .../SwURL/RemoteImage/RemoteImageView.swift | 23 +++++++++++-------- .../RemoteImage/TransitioningImage.swift | 2 -- Sources/SwURL/SwURL.swift | 10 ++++---- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Sources/SwURL/RemoteImage/Cache/FileManager+Paths.swift b/Sources/SwURL/RemoteImage/Cache/FileManager+Paths.swift index 38dd85a..9146fa1 100644 --- a/Sources/SwURL/RemoteImage/Cache/FileManager+Paths.swift +++ b/Sources/SwURL/RemoteImage/Cache/FileManager+Paths.swift @@ -8,9 +8,7 @@ import Foundation extension FileManager { - class func cachesDir() -> URL { - if let savedPath = UserDefaults.standard.url(forKey: "SwURLCacheDestinationDirectory") { return savedPath } else { @@ -21,5 +19,4 @@ extension FileManager { return url } } - } diff --git a/Sources/SwURL/RemoteImage/Cache/ImageCacheType.swift b/Sources/SwURL/RemoteImage/Cache/ImageCacheType.swift index 58ff15d..d940e23 100644 --- a/Sources/SwURL/RemoteImage/Cache/ImageCacheType.swift +++ b/Sources/SwURL/RemoteImage/Cache/ImageCacheType.swift @@ -10,11 +10,8 @@ import Combine import CoreGraphics public protocol ImageCacheType { - func store(image: CGImage, for url: URL) - func image(for url: URL) -> Future - } public enum ImageCache { diff --git a/Sources/SwURL/RemoteImage/Cache/InMemoryImageCache.swift b/Sources/SwURL/RemoteImage/Cache/InMemoryImageCache.swift index c4a17bd..af309c6 100644 --- a/Sources/SwURL/RemoteImage/Cache/InMemoryImageCache.swift +++ b/Sources/SwURL/RemoteImage/Cache/InMemoryImageCache.swift @@ -10,7 +10,6 @@ import SwiftUI import Combine public class InMemoryImageCache: ImageCacheType { - private let cache = NSCache() /// Specific queue to assist with concurrency. diff --git a/Sources/SwURL/RemoteImage/RemoteImageView.swift b/Sources/SwURL/RemoteImage/RemoteImageView.swift index 8b2ec2d..1c9b89c 100644 --- a/Sources/SwURL/RemoteImage/RemoteImageView.swift +++ b/Sources/SwURL/RemoteImage/RemoteImageView.swift @@ -10,25 +10,28 @@ import Foundation import SwiftUI public struct RemoteImageView: View { - + var url: URL - var placeholderImage: Image? let transitionType: ImageTransitionType - + @ObservedObject var remoteImage: RemoteImage = RemoteImage() public var body: some View { - TransitioningImage.init(placeholder: placeholderImage?.resizable(), - finalImage: remoteImage.load(url: url).image?.resizable(), - transitionType: transitionType) + TransitioningImage.init( + placeholder: placeholderImage?.resizable(), + finalImage: remoteImage.load(url: url).image?.resizable(), + transitionType: transitionType + ) } - - public init(url: URL, - placeholderImage: Image? = nil, - transition: ImageTransitionType = .none) { + + public init( + url: URL, + placeholderImage: Image? = nil, + transition: ImageTransitionType = .none + ) { self.placeholderImage = placeholderImage self.url = url self.transitionType = transition diff --git a/Sources/SwURL/RemoteImage/TransitioningImage.swift b/Sources/SwURL/RemoteImage/TransitioningImage.swift index ec2414a..ce07a45 100644 --- a/Sources/SwURL/RemoteImage/TransitioningImage.swift +++ b/Sources/SwURL/RemoteImage/TransitioningImage.swift @@ -8,9 +8,7 @@ import Foundation import SwiftUI - struct TransitioningImage: View { - var placeholder: Image? var finalImage: Image? diff --git a/Sources/SwURL/SwURL.swift b/Sources/SwURL/SwURL.swift index 83bdeb4..d062148 100644 --- a/Sources/SwURL/SwURL.swift +++ b/Sources/SwURL/SwURL.swift @@ -1,16 +1,16 @@ import Combine import Foundation - public struct SwURL { - private static let networker = Networker() - static func requestDecodable(from url: URL, - decoder: JSONDecoder = JSONDecoder()) -> AnyPublisher { + static func requestDecodable( + from url: URL, + decoder: JSONDecoder = JSONDecoder() + ) -> AnyPublisher { return networker.requestDecodable(from: url, decoder: decoder) } - + public static func setImageCache(type: ImageCache) { ImageLoader.shared.cache = type.cache }