Skip to content

Commit 5548e9d

Browse files
committed
Support init with optional url
1 parent a719545 commit 5548e9d

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Example/SDWebImageSwiftUIDemo/ContentView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ struct ContentView: View {
1414

1515
var body: some View {
1616
VStack {
17-
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")!)
17+
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"))
1818
.scaledToFit()
1919
.frame(width: 300, height: 300, alignment: .center)
20-
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif")!)
20+
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"))
2121
// .scaledToFit() // Apple's Bug ? Custom UIView does not passthrough the `contentMode` from Swift UI layout system into UIKit layout system
2222
.frame(width: 400, height: 300, alignment: .center)
2323
}

SDWebImageSwiftUI/Classes/AnimatedImage.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public struct AnimatedImage: ViewRepresentable {
6565
}
6666
}
6767

68-
public init(url: URL, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
68+
public init(url: URL?, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
6969
self.url = url
7070
}
7171

SDWebImageSwiftUI/Classes/ImageManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class ImageManager : ObservableObject {
2626
}
2727
}
2828

29-
var url: URL
29+
var url: URL?
3030
var options: SDWebImageOptions
3131
var context: [SDWebImageContextOption : Any]?
3232

33-
init(url: URL, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
33+
init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
3434
self.url = url
3535
self.options = options
3636
self.context = context

SDWebImageSwiftUI/Classes/WebImage.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import SwiftUI
1010
import SDWebImage
1111

1212
public struct WebImage : View {
13-
public var url: URL
13+
public var url: URL?
1414
public var placeholder: Image?
1515
public var options: SDWebImageOptions
1616
public var context: [SDWebImageContextOption : Any]?
1717

1818
@ObservedObject var imageManager: ImageManager
1919

20-
public init(url: URL, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
20+
public init(url: URL?, placeholder: Image? = nil, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil) {
2121
self.url = url
2222
self.placeholder = placeholder
2323
self.options = options

0 commit comments

Comments
 (0)