Skip to content

Commit

Permalink
some cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Callum Trounce committed Sep 18, 2019
1 parent e1fdf5e commit bcf9d2f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
3 changes: 0 additions & 3 deletions Sources/SwURL/RemoteImage/Cache/FileManager+Paths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import Foundation

extension FileManager {

class func cachesDir() -> URL {

if let savedPath = UserDefaults.standard.url(forKey: "SwURLCacheDestinationDirectory") {
return savedPath
} else {
Expand All @@ -21,5 +19,4 @@ extension FileManager {
return url
}
}

}
3 changes: 0 additions & 3 deletions Sources/SwURL/RemoteImage/Cache/ImageCacheType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import Combine
import CoreGraphics

public protocol ImageCacheType {

func store(image: CGImage, for url: URL)

func image(for url: URL) -> Future<CGImage, ImageLoadError>

}

public enum ImageCache {
Expand Down
1 change: 0 additions & 1 deletion Sources/SwURL/RemoteImage/Cache/InMemoryImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SwiftUI
import Combine

public class InMemoryImageCache: ImageCacheType {

private let cache = NSCache<NSURL, CGImage>()

/// Specific queue to assist with concurrency.
Expand Down
23 changes: 13 additions & 10 deletions Sources/SwURL/RemoteImage/RemoteImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Sources/SwURL/RemoteImage/TransitioningImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import Foundation
import SwiftUI


struct TransitioningImage: View {

var placeholder: Image?
var finalImage: Image?

Expand Down
10 changes: 5 additions & 5 deletions Sources/SwURL/SwURL.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Combine
import Foundation


public struct SwURL {

private static let networker = Networker()

static func requestDecodable<T: Decodable>(from url: URL,
decoder: JSONDecoder = JSONDecoder()) -> AnyPublisher<T, Error> {
static func requestDecodable<T: Decodable>(
from url: URL,
decoder: JSONDecoder = JSONDecoder()
) -> AnyPublisher<T, Error> {
return networker.requestDecodable(from: url, decoder: decoder)
}

public static func setImageCache(type: ImageCache) {
ImageLoader.shared.cache = type.cache
}
Expand Down

0 comments on commit bcf9d2f

Please sign in to comment.