-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
Cannot override ImageDisplayingView method in UIImageView subclass #38
Comments
Ok, I've just tested it and I can confirm that Swift calls the default implementation provided in |
As a workaround you can set a custom handler on ImageViewLoadingController: class CustomImageView: UIImageView {
override init(frame: CGRect) {
super.init(frame: frame)
self.nk_imageLoadingController.handler = { task, response, options in
// your nk_imageTask(task: ImageTask, didFinishWithResponse response: ImageResponse, options: ImageViewLoadingOptions?) implementation
}
}
} |
Thank, Kean, that works great. Want me to close the issue or will you leave it open to investigate? |
Please leave it open. Users should be able to override methods declared in ImageDisplayingView protocol, at least that was the intended behaviour. I should figure out why virtual dispatch doesn't work here. |
After some research I've found several different issues related to methods dispatch with protocol extensions that still hasn't been fixed in Xcode 7. Here's the related one http://www.openradar.me/23067007. You have class And that's how it works in Nuke:
extension UIImageView: ImageDisplayingView, ImageLoadingView {
public var nk_image: UIImage? {
get { return self.image }
set { self.image = newValue }
}
public func nk_imageTask(task: ImageTask, didFinishWithResponse response: ImageResponse, options: ImageViewLoadingOptions?) {
print("UIImageView method called")
}
}
public class NKImageView: UIImageView {
}
extension NKImageView {
public override var nk_image: UIImage? {
get { return self.image }
set { self.image = newValue }
}
public func nk_imageTask(task: ImageTask, didFinishWithResponse response: ImageResponse, options: ImageViewLoadingOptions?) {
print("NKImageView method never gets called")
}
}
The error message is pretty obvious. And as you can see properties already can be overridden and get called as expected. |
This behaviour (http://www.openradar.me/23067007) doesn't match the documentation that clearly states that:
Same thing holds with extensions with
|
I'm trying to wrap the Nuke functionality in my own UIImageView subclass. Due to
ImageLoadingViewExtensions.swift
, I am unable to override the thefunc nk_imageTask(task: ImageTask, didFinishWithResponse response: ImageResponse, options: ImageViewLoadingOptions?)
where I want to place some custom logic.Is there any way this can be changed to allow me to do that?
The text was updated successfully, but these errors were encountered: