There are Objective-C libraries with functions that take integer enum options as a parameter, but they expect you to pass 0 in if you want default options, as is typical. But in Swift, that is not allowed because the library specifies an enum type. Is there any way around this short of adding a 0 enum option to the libraries then making bridging code to make its ObjC enums work in Swift?
Here's an example with SDWebImageManager
in an iPhone app:
SDWebImageManager.sharedManager().downloadWithURL(url, options: 0, progress: nil) { (image:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool) -> Void in
// block code here
}
Xcode will point out an error where it says options: 0
because 'Int' is not convertible to SDWebImageOptions
. I've tried something like the following, but I get the same error:
let emptyOptions:SDWebImageOptions = 0
As of Swift 2, the syntax for option sets was changed to use array literals. So if you want to pass no options, you pass an empty list:
SDWebImageManager.sharedManager().downloadWithURL(url, options: [], progress: nil) { (image:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool) -> Void in
// code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With