You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want complete control over the service responsible for managing the state of the view and for fetching the image you could pass an object conforming to the `RemoteImageService` to the related initializer:
60
+
Under the hood the `URLSession.shared` is used by default as the `RemoteImageURLDataPublisher` to fetch the image at the specified URL.
61
+
You can specify a custom publisher through the`remoteImageURLDataPublisher` parameter.
62
+
As an example that's how you could add support for low data mode to the `RemoteImage` view.
61
63
62
64
```swift
63
65
let url =URL(string: "https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80")!
64
66
65
-
RemoteImage(type: .url(url), service: yourCustomService, errorView: { error in
Under the hood by default the `URLSession.shared` is used as the `RemoteImageURLDataPublisher` to fetch the image at the specified URL.
79
-
You can specify a custom publisher through the`remoteImageURLDataPublisher` parameter.
80
-
As an example that's how you could add support for low data mode to the `RemoteImage` view.
85
+
If you want complete control over the service responsible for managing the state of the view and for fetching the image you could pass an object conforming to the `RemoteImageService` protocol to the related initializer:
let url =URL(string: "https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80")!
RemoteImage(type: .url(url), service: CustomService(), errorView: { error in
93
+
Text(error.localizedDescription)
94
+
}, imageView: { image in
95
+
image
96
+
.resizable()
97
+
.aspectRatio(contentMode: .fit)
98
+
}, loadingView: {
99
+
Text("Loading ...")
100
+
})
101
+
```
102
+
103
+
In addition to that you could use the new `@StateObject` property wrapper introcuded in Swift by creating an instance of the default built-in `RemoteImageService` and using the above initializer:
104
+
105
+
```swift
106
+
@StateObjectvar service = DefaultRemoteImageServiceFactory.makeDefaultRemoteImageService()
107
+
// or
108
+
@StateObjectvar service = DefaultRemoteImageServiceFactory.makeDefaultRemoteImageService(remoteImageURLDataPublisher: yourRemoteImageURLDataPublisher)
109
+
110
+
let url =URL(string: "https://images.unsplash.com/photo-1524419986249-348e8fa6ad4a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80")!
111
+
112
+
RemoteImage(type: .url(url), service: service, errorView: { error in
0 commit comments