Closed mesheilah closed 4 years ago
You need :
import SDWebImageSwiftUI
import SDWebImage
The SDWebImageSwiftUI does not have a @_exported import SDWebImage
to automatically do this.
Maybe I can added one in 1.3.2 version ? Any idea or PR ?
@mesheilah
Maybe this can help: #100
Note: Previous version you don't need import SDWebImage as well, if you use CocoaPods or Carthage. This is SwiftPM's only issue because SwiftPM can not contains Swift && Objc code at the same target.
We already import SDWebImage in SDWebImageSwiftUI.h
umbrella headers (available in CocoaPods && Carthage user)
@dreampiggy yeah I thought it was an issue with SwiftPM too. However, regarding the custom header thing, is there a way to include it for some images rather than in AppDelegate for all images ?
Maybe I don't correctly understand your use case ?
You mean: "Can I choose only use A decoder to this URL, instead of register the coder plugin globally" ?
Use context option [.imageCoder : SDImageSVGCoder.shared]
solve this.
or means the custom header for single image URL request ?
Use context option [.requestModifier : MyHTTPHeaderModifier]
solve this.
Request Modifier is a powerful tool beyond just HTTP header. You can modify the HTTP Method (for example, HEAD, POST, instead of default GET method), HTTP Body, allowsCellularAccess, allowsExpensiveNetworkAccess for low data mode, etc.
Type 'SDWebImageContextOption' has no member 'requestModifier'
error fires
it must be downloadRequestModifier
not requestModifier
this change makes it compile.
Sorry the strange naming :)...In the future this context option will become a Swift enum with associated value.
See more https://github.com/SDWebImage/SDWebImage/issues/2980
so to wrap up, a simple usage for this option is:
[.downloadRequestModifier: SDWebImageDownloaderRequestModifier(block: { (request) -> URLRequest? in
var request = request
request.setValue("MyValue", forHTTPHeaderField: "MyHeader")
return request
})]
Yes. Use Swift closure syntax can simply to
[.downloadRequestModifier: SDWebImageDownloaderRequestModifier {
var request = $0
request.setValue("MyValue", forHTTPHeaderField: "MyHeader")
return request
}]
The request modifier is powerful, and can be reused. So this is why it design like that.
Maybe can have a single convience one like .HTTPHeader : ["Foo" : "bar"]
which translate to this in future Swift API.
But things become complicated when you pass a Dictionary
However, HTTP 2.0 disable CAPITAL and must in lower cases. (See HTTP 2 Spec, or some blogs: https://blog.yaakov.online/http-2-header-casing/) So, if you write:
let options = [.HTTPHeader : ["Foo": "Bar", "foo" : "bar"]]
This will cause a misunderstanding...Actually there will be only one foo:bar
in HTTP 2 request.
@mesheilah 1.3.2 version released. Please upgrade, so that you don't need to manually import SDWebImage.
@mesheilah SDWebImage 5.8.0 released. Which added the convenient API for HTTP header request/response modifier. See full changelog: https://github.com/SDWebImage/SDWebImage/releases/tag/5.8.0
I've read your wiki on how to set a default header, but the class
SDWebImageDownloader
itself isn't available withSDWebImageSwiftUI
namespace, or there is maybe some kind of necessary import that I'm not aware of ? plus, I need to pass a user token with some images but not all images in the app, so it's not going to be a default header set in AppDelegate, but rather a custom header for some cases, I couldn't find a way to a pass a custom header withSDWebImageSwiftUI