Skip to content

Commit 3a0995b

Browse files
committed
Update the readme demo code to use swifty syntax
1 parent 2b1ac93 commit 3a0995b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Example/SDWebImageSwiftUIDemo/ContentView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ struct ContentView: View {
9494
}
9595
}
9696
}
97-
.onDelete(perform: { (indexSet) in
98-
indexSet.forEach { (index) in
97+
.onDelete { indexSet in
98+
indexSet.forEach { index in
9999
self.imageURLs.remove(at: index)
100100
}
101-
})
101+
}
102102
}
103103
}
104104

Example/SDWebImageSwiftUIDemo/DetailView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@ struct DetailView: View {
5353
HStack {
5454
if animated {
5555
AnimatedImage(url: URL(string:url), options: [.progressiveLoad], isAnimating: $isAnimating)
56-
.onProgress(perform: { (receivedSize, expectedSize) in
56+
.onProgress { receivedSize, expectedSize in
5757
// SwiftUI engine itself ensure the main queue dispatch
58-
if (expectedSize >= 0) {
58+
if (expectedSize > 0) {
5959
self.progress = CGFloat(receivedSize) / CGFloat(expectedSize)
6060
} else {
6161
self.progress = 1
6262
}
63-
})
63+
}
6464
.resizable()
6565
.scaledToFit()
6666
} else {
6767
WebImage(url: URL(string:url), options: [.progressiveLoad])
68-
.onProgress(perform: { (receivedSize, expectedSize) in
69-
if (expectedSize >= 0) {
68+
.onProgress { receivedSize, expectedSize in
69+
if (expectedSize > 0) {
7070
self.progress = CGFloat(receivedSize) / CGFloat(expectedSize)
7171
} else {
7272
self.progress = 1
7373
}
74-
})
74+
}
7575
.resizable()
7676
.scaledToFit()
7777
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Note: Unlike `UIImageView` in UIKit, SwiftUI's `Image` does not support animatio
7171
```swift
7272
var body: some View {
7373
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"))
74-
.onSuccess(perform: { (image, cacheType) in
74+
.onSuccess { image, cacheType in
7575
// Success
76-
})
76+
}
7777
.resizable()
7878
.scaledToFit()
7979
.frame(width: 300, height: 300, alignment: .center)
@@ -87,9 +87,9 @@ var body: some View {
8787
Group {
8888
// Network
8989
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"))
90-
.onFailure(perform: { (error) in
90+
.onFailure { error in
9191
// Error
92-
})
92+
}
9393
.scaledToFit()
9494
// Data
9595
AnimatedImage(data: try! Data(contentsOf: URL(fileURLWithPath: "/tmp/foo.webp")))

0 commit comments

Comments
 (0)