New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a bug in swift3 #1764
Comments
No response? |
@Mosaics facing same problem, any workaround you found? |
@rs @phiren As I said, via swift class point into your method You will find, as shown in figure, your options option is that there is a default empty array value, based on the characteristics of swift have default values are not pass parameters will be at the time of writing this method automatically appear two kinds, one kind is with this parameter, one kind is not belt, when he appeared with no arguments, in fact just write another way to conflict with you, it don't understand what you are using which method (is to ignore parameters method with options or no options that method), since the OC can be identified, suggest the swift, don't give this method directly the option of the initial value, forcing the incoming.This may be a solution.In fact, because of swift this feature, I was surprised that the other way to solve this problem.But I don't know this change whether the framework has big influence on you? |
@Mosaics got your point, i was trying without the options. As i tried with options, now it giving me other error |
@phiren Maybe you understand the wrong I mean, this is not a framework user error, but the framework itself is a defect.If must avoid, also for your usage, I didn't find there is a mistake.As shown in figure: |
I will look at this soon (also marked it for 4.1.0). In the meantime, see #1627 |
I've doing some research on this. Turns out it isn't really that easy. The key, which has been point out by @Mosaics is that Swift has internal support for default values of method parameters. This feature does not play well with those methods signatures in In most cases, this will simply cause redundancy, because the interoperation mechanism in Swift can convert nullable method parameters in Objective-C into default value To resolve this, my suggestion would be creating a new interface for Swift, utilizing - (void)sd_setImageWithURL:(nullable NSURL *)url NS_SWIFT_UNAVAILABLE("Use refined method for Swift instead");
- (void)sd_setImageWithURL:(nullable NSURL *)url
placeholderImage:(nullable UIImage *)placeholder NS_SWIFT_UNAVAILABLE("Use refined method for Swift instead");
//...
// We only need the last one.
- (void)sd_setImageWithURL:(nullable NSURL *)url
placeholderImage:(nullable UIImage *)placeholder
options:(SDWebImageOptions)options
progress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
completed:(nullable SDExternalCompletionBlock)completedBlock NS_REFINED_FOR_SWIFT; Second, create new Swift interface like this: extension UIImageView {
func sd_setImage(url: URL?, placeholderImage: UIImage? = nil, options: SDWebImageOptions = .init(rawValue: 0), progress: SDWebImageDownloaderProgressBlock? = nil, completed: SDExternalCompletionBlock? = nil) {
__sd_setImage(with: url, placeholderImage: placeholderImage, options: options, progress: progress, completed: completed)
}
} To avoid signature collision, the method is named Now, old methods won't show up in the IDE auto-completion and using those methods will be forbidden by compiler:
Seems to me there is no other way to do this without creating a new Swift interface. That being said, I really don't like adding Swift source files into pure Objective-C libraries. One concern would be that once you have a Swift file in your library you can not use it as a pure static library any more. You'll have to use it as a dynamic (or embedded in Apple's dictionary) Framework. And you'll have to make your target iOS 8+ because embedded framework works only on iOS8+. This kind of sucks if you need to support lower version of iOS. I thought about perhaps making a CC @bpoplauschi |
@skyline75489 thanks for looking into this, your solution sounds like it can work and take care of the issue. Are you available for making a PR with this? |
PS: Regarding a Swift subspec, CocoaLumberjack does the same and it works (not ideal solution but a working one). @skyline75489 couldn't we mark as |
If I'm not misunderstanding this, we can and probably should do that in each category(e.g. I'll try to make a PR tonight. |
@bpoplauschi Seems like I've been misunderstanding your point. You mean just mark |
@skyline75489 yeah, that was my point. For now, I would just go with the simple solution (no Swift). Especially because it seems that your branch keeps failing at building in Travis at this |
@bpoplauschi Alright then. I'll go and make a more simple fix. The Swift way is actually way more complicated than I thought. And I finally understand why CocoaLumberjack is using a separate Swift framework because otherwise many other problems would arise. |
Exactly. And thanks |
@bpoplauschi I've been trying to come up with a Objective-C only fix. But the result is not very ideal. The generated Swift method signature for the method that have all the parameters looks like this: open func sd_setImage(with url: URL?, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], progress progressBlock: SDWebImage.SDWebImageDownloaderProgressBlock?, completed completedBlock: SDWebImage.SDExternalCompletionBlock? = nil) As you can see only the |
The ObjC interface would look like this:
and the generated Swift interface
How does this sound? |
This fixes |
And by the way, using
It seems that Xcode still know the short version is there but refuses to let you use it, which is kind of strange and here just not correct for us. I think |
I'm not too worried about |
About
|
As for For This can work as well. |
Last comment from this burst :)
|
@rs
Encounter problems as shown in the swift3 use, I think it's because your placeholder parameter has a default value, because of swift characteristics, can not pass parameters have default values.Cause it doesn't know what the hell am I was in use which method.Can you repair?
See I upload pictures
The text was updated successfully, but these errors were encountered: