2

I want to push swift UIViewController from my objective C uiviewcontroller and wait for that viewcontroller to send back data. How can I do it.

I tried using protocol/Delegate in swift but it throws error as it is not available in objc .h file even if I'm importing "Pass-swift.h" bridging header file.

I am curious if there I can do with completion blocks if yes then how? or any other approach?

//Parentviewcontroller.m file


- (void)sendNextbutton:(id)sender{

UIViewController *vc = [[SecurityQuestionViewController alloc] init];

[self.navigationController pushViewController:vc animated:YES];

// I want below signup  function to calll after getting data back from vc viewcontoller
[self singupWithSecurityQuestion];}

// .h file

#import  "PassSDK-Swift.h"


@interface ParentViewController : UIViewController <MyProtocol>

@end

//SecurityQuestionViewController.swift

 @objc protocol MyProtocol {
   func setResultofSecurityQuestion(valueSent: [NSDictionary])
 }

@objc public class SecurityQuestionViewController: UIViewController
{    
  var delegate: MyProtocol?

@objc func didTapSubmitButton(sender: UIButton){
    let data: [NSDictionary] = getQuesDictionary()
    print(data)
    delegate?.setResultofSecurityQuestion(valueSent: data)
    navigationController?.popViewController(animated: true)
    dismiss(animated: true, completion: nil)
  }

}

//I should get data back to ParentViewController and it should wait for swift view controller to send back data and then it should go to next function/method - singupWithSecurityQuestion.

Reed
  • 944
  • 7
  • 15
  • As a rule of thumb, try adding `@objc` everywhere: before the `func`, before the `var delegate` -- see if it helps. – Yonat Sep 29 '19 at 08:23

1 Answers1

0

so the answer is that to use

       @objc protocol MyProtocol: class {
  func setResultofSecurityQuestion(valueSent: [NSDictionary])
          }

and @objc everywhere

Reed
  • 944
  • 7
  • 15