iOS API Function UIImageWriteToSavedPhotosAlbum
takes a selector as one argment:
func UIImageWriteToSavedPhotosAlbum(_ image: UIImage,
_ completionTarget: Any?,
_ completionSelector: Selector?,
_ contextInfo: UnsafeMutableRawPointer?)
https://developer.apple.com/documentation/uikit/1619125-uiimagewritetosavedphotosalbum
However, in swift, when I call this function, the selector never gets recognized:
class Base {
func save_image(img:UIImage) {
UIImageWriteToSavedPhotosAlbum(img, self, Selector("image:didFinishSavingWithError:contextInfo:"), nil)
// I also tried this:
// UIImageWriteToSavedPhotosAlbum(img, self, #selector(image(_:didFinishSavingWithError:contextInfo:))
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
print("Photo Saved Successfully")
}
}
class Child:Base {
}
// This is how I call the save_image function:
let child = Child()
child.save_image()
As you can see, I tried constructing the selector from the signature, and from a string, but neither works. I always get this error in runtime:
'XXX.Child' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector ......
What is happening here? I am wondering if this is because swift doesn't see the method from the Child class, as the method is inherited from Base class?
How can I pass the selector successfully?
Relevant question I have read: