From this answer there seems to be a way to pass data back to a prior View Controller using a Swift closure that is way simpler than using delegates.
Given that the Swift closure is similar to using blocks in Objective-C, how can I do this in my Objective-C project? I don't know Swift and delegate approach seems overly complicated to set one property.
Here is the Swift code:
For sending a UIImage back in my case. In ViewControllerA:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cropImageViewController = segue.destinationViewController as! CropImageViewController
cropImageViewController.choseImage = { image in
//Do what you want in here!
}
}
In ViewControllerB:
var choseImage : (UIImage -> Void)?
@IBAction func done(sender: AnyObject) {
choseImage?(croppedImage)
self.dismissViewControllerAnimated(true, completion: nil)
}
I can pass data forward using Prepare for Segue in Objective-C but am stumped on how to pass it backwards.
//launch VC
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"edit"]) {
...
destViewController.contact=contact;
}
//set property in presentingVC--THIS DOES NOT WORK.
self.presentingViewController.afterSave = YES;
[self dismissViewControllerAnimated:YES completion:nil];