Skip to content

Commit 7de2045

Browse files
author
Chris
authored
Merge pull request #18 from crelies/dev
4.0.0
2 parents 0a77464 + 868644b commit 7de2045

22 files changed

+155
-170
lines changed

Sources/RemoteImage/private/Models/RemoteImageState.swift

Lines changed: 0 additions & 31 deletions
This file was deleted.

Sources/RemoteImage/private/Protocols/RemoteImageServiceProtocol.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.

Sources/RemoteImage/private/Protocols/RemoteImageURLDataPublisher.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// DefaultRemoteImageServiceDependencies.swift
3+
// RemoteImage
4+
//
5+
// Created by Christian Elies on 29.10.19.
6+
//
7+
8+
import Foundation
9+
10+
protocol DefaultRemoteImageServiceDependenciesProtocol: PhotoKitServiceProvider, RemoteImageURLDataPublisherProvider {
11+
12+
}
13+
14+
struct DefaultRemoteImageServiceDependencies: DefaultRemoteImageServiceDependenciesProtocol {
15+
let photoKitService: PhotoKitServiceProtocol
16+
let remoteImageURLDataPublisher: RemoteImageURLDataPublisher
17+
18+
init(remoteImageURLDataPublisher: RemoteImageURLDataPublisher) {
19+
photoKitService = PhotoKitService()
20+
self.remoteImageURLDataPublisher = remoteImageURLDataPublisher
21+
}
22+
}

Sources/RemoteImage/private/Services/PhotoKitService.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ protocol PhotoKitServiceProvider {
1212
}
1313

1414
protocol PhotoKitServiceProtocol {
15-
func getPhotoData(localIdentifier: String,
16-
_ completion: @escaping (Result<Data, Error>) -> Void)
15+
func getPhotoData(
16+
localIdentifier: String,
17+
_ completion: @escaping (Result<Data, Error>) -> Void
18+
)
1719
}
1820

1921
final class PhotoKitService {
@@ -22,8 +24,10 @@ final class PhotoKitService {
2224
}
2325

2426
extension PhotoKitService: PhotoKitServiceProtocol {
25-
func getPhotoData(localIdentifier: String,
26-
_ completion: @escaping (Result<Data, Error>) -> Void) {
27+
func getPhotoData(
28+
localIdentifier: String,
29+
_ completion: @escaping (Result<Data, Error>) -> Void
30+
) {
2731
let fetchAssetsResult = Self.asset.fetchAssets(withLocalIdentifiers: [localIdentifier], options: nil)
2832
guard let phAsset = fetchAssetsResult.firstObject else {
2933
completion(.failure(PhotoKitServiceError.phAssetNotFound(localIdentifier: localIdentifier)))

Sources/RemoteImage/private/Services/RemoteImageServiceDependencies.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

Sources/RemoteImage/private/Extensions/URLSession+RemoteImageURLDataPublisher.swift renamed to Sources/RemoteImage/public/Extensions/URLSession+RemoteImageURLDataPublisher.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Combine
99
import Foundation
1010

1111
extension URLSession: RemoteImageURLDataPublisher {
12-
func dataPublisher(for request: URLRequest) -> AnyPublisher<(data: Data, response: URLResponse), URLError> {
13-
dataTaskPublisher(for: request).eraseToAnyPublisher()
12+
public func dataPublisher(for url: URL) -> AnyPublisher<(data: Data, response: URLResponse), URLError> {
13+
dataTaskPublisher(for: url).eraseToAnyPublisher()
1414
}
1515
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// RemoteImageState.swift
3+
// RemoteImage
4+
//
5+
// Created by Christian Elies on 11.08.19.
6+
// Copyright © 2019 Christian Elies. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum RemoteImageState: Hashable {
12+
case error(_ error: NSError)
13+
case image(_ image: UniversalImage)
14+
case loading
15+
}

Sources/RemoteImage/public/Models/RemoteImageType.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99

1010
public enum RemoteImageType {
11+
@available(*, deprecated, message: "Will be removed in the future because the localIdentifier is device specific and therefore cannot be used to uniquely identify a PHAsset across devices.")
1112
case phAsset(localIdentifier: String)
1213
case url(_ url: URL)
1314
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// RemoteImageService.swift
3+
// RemoteImage
4+
//
5+
// Created by Christian Elies on 15.12.19.
6+
//
7+
8+
import Combine
9+
10+
public typealias RemoteImageCacheKeyProvider = (RemoteImageType) -> AnyObject
11+
12+
/// Represents the service associated with a `RemoteImage` view. Responsible for fetching the image and managing the state.
13+
public protocol RemoteImageService where Self: ObservableObject {
14+
/// The cache for the images fetched by any instance of `RemoteImageService`.
15+
static var cache: RemoteImageCache { get set }
16+
/// Provides a key for a given `RemoteImageType` used for storing an image in the cache.
17+
static var cacheKeyProvider: RemoteImageCacheKeyProvider { get set }
18+
19+
/// The current state of the image fetching process - `loading`, `error` or `image (success)`.
20+
var state: RemoteImageState { get set }
21+
22+
/// Fetches the image with the given type.
23+
///
24+
/// - Parameter type: Specifies the source type of the remote image. Choose between `.url` or `.phAsset`.
25+
func fetchImage(ofType type: RemoteImageType)
26+
}

0 commit comments

Comments
 (0)