Aggressor Aggressor - 4 months ago 47
Swift Question

UIImageWriteToSavedPhotosAlbum Selector Syntax Issue

Trying hard to get UIImageWriteToSavedPhotosAlbum to work in swift https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKitFunctionReference/index.html#//apple_ref/c/func/UIImageWriteToSavedPhotosAlbum

The documentation is sadly ONLY in objective C.

Here is my code:

func saveImage()
{
UIImageWriteToSavedPhotosAlbum(uiimage, self, "saveImageComplete:::", nil)
}

func saveImageComplete(image:UIImage,err:NSError,context:UnsafePointer<()>)
{
loadLastPhotoIntoGalleryIcon()
}


But the problem is that it throws the NSInvalidArgumentException with an unrecognized selector:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'app.PhotoEditor<0x14a1e400> does not respond to selector
saveImageComplete:::'


Can you advise what is wrong with my syntax and how I properly specific this selector? From what I understand, each : represents 1 argument the method expects and since it has 3 parameters I gave it 3 :'s.

Thanks!

Answer

If your method were an Objective-C method, the selector would be something like "saveImageCompleteImage:err:context:". You need to remember that the parameters are part of the name in Objective-C, so "saveImageComplete:::" doesn't specify a method that could be called saveImageComplete(image:UIImage,err:NSError,context:UnsafePointer<()>) in Swift.

Comments