Skip to content

Commit 868644b

Browse files
author
Christian Elies
committed
docs(): added some basic code documentation
1 parent 059657c commit 868644b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

Sources/RemoteImage/public/Protocols/RemoteImageService.swift

+8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ import Combine
99

1010
public typealias RemoteImageCacheKeyProvider = (RemoteImageType) -> AnyObject
1111

12+
/// Represents the service associated with a `RemoteImage` view. Responsible for fetching the image and managing the state.
1213
public protocol RemoteImageService where Self: ObservableObject {
14+
/// The cache for the images fetched by any instance of `RemoteImageService`.
1315
static var cache: RemoteImageCache { get set }
16+
/// Provides a key for a given `RemoteImageType` used for storing an image in the cache.
1417
static var cacheKeyProvider: RemoteImageCacheKeyProvider { get set }
1518

19+
/// The current state of the image fetching process - `loading`, `error` or `image (success)`.
1620
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`.
1725
func fetchImage(ofType type: RemoteImageType)
1826
}

Sources/RemoteImage/public/Views/RemoteImage.swift

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import Combine
1111
import SwiftUI
1212

13+
/// A custom Image view for remote images with support for a loading and error state.
1314
public struct RemoteImage<ErrorView: View, ImageView: View, LoadingView: View, Service: RemoteImageService>: View {
1415
private let type: RemoteImageType
1516
private let errorView: (Error) -> ErrorView
@@ -33,14 +34,14 @@ public struct RemoteImage<ErrorView: View, ImageView: View, LoadingView: View, S
3334
}
3435
}
3536

36-
/// <#Description#>
37+
/// Initializes the view with the given values, especially with a custom `RemoteImageService`.
3738
///
3839
/// - Parameters:
39-
/// - type: <#type description#>
40-
/// - service: <#service description#>
41-
/// - errorView: <#errorView description#>
42-
/// - imageView: <#imageView description#>
43-
/// - loadingView: <#loadingView description#>
40+
/// - type: Specifies the source type of the remote image. Choose between `.url` or `.phAsset`.
41+
/// - service: An object conforming to the `RemoteImageService` protocol. Responsible for fetching the image and managing the state.
42+
/// - errorView: A view builder used to create the view displayed in the error state.
43+
/// - imageView: A view builder used to create the `Image` displayed in the image state.
44+
/// - loadingView: A view builder used to create the view displayed in the loading state.
4445
public init(type: RemoteImageType, service: Service, @ViewBuilder errorView: @escaping (Error) -> ErrorView, @ViewBuilder imageView: @escaping (Image) -> ImageView, @ViewBuilder loadingView: @escaping () -> LoadingView) {
4546
self.type = type
4647
self.errorView = errorView
@@ -53,14 +54,14 @@ public struct RemoteImage<ErrorView: View, ImageView: View, LoadingView: View, S
5354
}
5455

5556
extension RemoteImage where Service == DefaultRemoteImageService {
56-
/// <#Description#>
57+
/// Initializes the view with the given values. Uses the built-in `DefaultRemoteImageService`.
5758
///
5859
/// - Parameters:
59-
/// - type: <#type description#>
60-
/// - remoteImageURLDataPublisher: <#remoteImageURLDataPublisher description#>
61-
/// - errorView: <#errorView description#>
62-
/// - imageView: <#imageView description#>
63-
/// - loadingView: <#loadingView description#>
60+
/// - type: Specifies the source type of the remote image. Choose between `.url` or `.phAsset`.
61+
/// - remoteImageURLDataPublisher: An object conforming to the `RemoteImageURLDataPublisher` protocol, by default `URLSession.shared` is used.
62+
/// - errorView: A view builder used to create the view displayed in the error state.
63+
/// - imageView: A view builder used to create the `Image` displayed in the image state.
64+
/// - loadingView: A view builder used to create the view displayed in the loading state.
6465
public init(type: RemoteImageType, remoteImageURLDataPublisher: RemoteImageURLDataPublisher = URLSession.shared, @ViewBuilder errorView: @escaping (Error) -> ErrorView, @ViewBuilder imageView: @escaping (Image) -> ImageView, @ViewBuilder loadingView: @escaping () -> LoadingView) {
6566
self.type = type
6667
self.errorView = errorView

0 commit comments

Comments
 (0)