1 min readApr 12, 2018
I’m using solution similar to yours for a while.
While using it I notice one problem. If you copy DelegatedCall struct you can call closure outside of owner.
Eg:
class Controller {
let downloader = ImageDownloader()
var image: UIImage?
init() {
downloader.didDownload.delegate(to: self) { (self, image) in
self.image = image
}
}
func updateImage() {
downloader.downloadImage(for: /* some image url */)
} func trickDownloader() {
var callback = downloader.didDownload
collback.callback?(NSImange()) // This invokes closure from init method
}}
Did you spot this problem and if so, do you have any solution to fix that?