iosswifttranslationcodeblocksuipickerviewcontroller

Block syntax translation problems Objective C to Swift


TWPhotoPickerController *photoPicker = [[TWPhotoPickerController alloc] init];
photoPicker.cropBlock = ^(UIImage *image) {
    //do something
};
[self presentViewController:photoPicker animated:YES completion:NULL];

Been stuck on this for way too long. I have imported all the correct header files into my bridging header file... just need to know how do I translate this block into swift syntax?


Solution

  • It should be something like this:

    var photoPicker = TWPhotoPickerController()
    photoPicker.cropBlock = { (image: UIImage) -> () in
    // do something
    }    
    presentViewController(photoPicker, animated: true, completion: nil)