Skip to content

Commit efbbf63

Browse files
committed
Add SwiftUI usage
1 parent 3deb524 commit efbbf63

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ imageView.setImage(url: imageUrl) { result in
7676

7777
`result` is an enum `Result` that let you know if the operation succeeded or failed. The possible error is of `ImaginaryError`.
7878

79+
## SwiftUI
80+
81+
#### Set image with URL
82+
83+
Simply pass `URL` to `ImageViewAdapter`.
84+
85+
```swift
86+
ImageViewAdapter(url: "https://avatars2.githubusercontent.com/u/1340892?v=3&s=200")
87+
```
88+
7989
## Advanced
8090

8191
### Passing option
@@ -99,7 +109,6 @@ public protocol ImageProcessor {
99109

100110
This is how you apply tint color before setting images.
101111

102-
103112
```swift
104113
let option = Option(imagePreprocessor: TintImageProcessor(tintColor: .orange))
105114
imageView.setImage(url: imageUrl, option: option)
@@ -142,15 +151,15 @@ These are the buit in displayers. You need to supply the correct displayer for y
142151

143152
### Downloading
144153

145-
`Imaginary` uses `ImageFetcher` under the hood, which has downloader and storage. You can specify your own `ImageDownloader` together with a `modifyRequest` closure, there you can change request body or add more HTTP headers.
154+
`Imaginary` uses `ImageFetcher` under the hood, which has downloader and storage. You can specify your own `ImageDownloader` together with a `modifyRequest` closure, there you can change request body or add more HTTP headers.
146155

147156
```swift
148157
var option = Option()
149158
option.downloaderMaker = {
150-
return ImageDownloader(modifyRequest: {
159+
return ImageDownloader(modifyRequest: {
151160
var request = $0
152161
request.addValue("Bearer 123", forHTTPHeaderField: "Authorization")
153-
return request
162+
return request
154163
})
155164
}
156165

@@ -220,7 +229,6 @@ multipleFetcher.fetch(urls: imageUrls, each: { result in
220229

221230
This is ideal for the new [prefetching mode in UICollectionView](https://developer.apple.com/documentation/uikit/uicollectionview/1771771-prefetchingenabled)
222231

223-
224232
## Installation
225233

226234
**Imaginary** is available through [CocoaPods](http://cocoapods.org). To install

0 commit comments

Comments
 (0)