Objective-C callback from Swift

In Swift application I have a

ViewController
, which call a new
modal
.

This

modal
have as
ViewController
Objective-C
implementation as
ViewController_obj_c
.

This

modal
is shown from Swift code and I want to call the callback property (with UIImage paramter), when the
Objective-C
code is done.


Me callback property

"signCompleteCallback"
doesn't work. How can I fill a callback property from
Swift
and call it inside
Objective-C
?


SwiftViewController.swift:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  if segue.identifier == "showModalSegue" {
       if let nextVC = segue.destination as? ViewController_obj_c {

       nextVC.signCompleteCallback = #selector(self.Test) // filled objective-c selector here

       }
  }
}

@objc func Test(image: UIImage)
{
  debugPrint("Test method was called as callback with image parameter")
}


ViewController_obj_c.h:

@interface ViewController_obj_c : UIViewController 


@property SEL signCompleteCallback;

- (IBAction)Done_Clicked:(id)sender;


ViewController_obj_c.m:

- (IBAction)Done_Clicked:(UIButton *)sender
{
  UIGraphicsBeginImageContext(_dV.bounds.size);
  [_dV.layer renderInContext:UIGraphicsGetCurrentContext()];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  [self signCompleteCallback]; // Here is the point when i want to call me callback and as a parameter i want to send image
}
Accepted Answer

I have posted an answer to the equivalent question in the stackoverflow.com.

(stackoverflow.com/questions/51186716/swift-callback-from-objective-c)


Please check it.

For the record, the original problem is in this line:


  [self signCompleteCallback]; // Here is the point when i want to call me callback and as a parameter i want to send image


Since "signCompleteCallback" is a property, this line just gets the selector for the "callback", but doesn't do anything with it. If you wanted to invoke the method, you would do something like this:


  [self performSelector: [self signCompleteCallback] withObject: image];


However, OOPer's alternate solution is better all round.

Objective-C callback from Swift
 
 
Q