iosobjective-cswiftdelegatesobjective-c-framework

iOS Framework Delegate and IBAction are not getting called in Swift


I am creating one framework in Objective-C. I have everything working fine in Objective-C project. But when I Integrate my framework with Swift project, it behaves strange.

My Swift Project:

Now:

But when I tried to add NSTimer repeat method in viewDidAppear, everything working fine again.

I know this is very weird issue but might be someone has faced this.

My Code:

override func viewDidAppear(animated: Bool) {
    MySDK.sharedInstance().initWithAppKey("123")
    MySDK.sharedInstance().delegate = self

    NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "timer", userInfo: nil, repeats: true)
}

Delegate calls,

//This is getting called
func initSdkSuccessful() {
    MySDK.sharedInstance().doStuff()
}

//This is not getting called
func stuffDone() {

}

IBActions,

//This is getting called if I do not set delegate,but if I set delegate to self then It doesn't.
@IBAction func btnTapped(sender: UIButton) {
    MySDK.sharedInstance().doAnotherStuff()
}

Thanks


Solution

  • I found the solution which was really very simple one,

    Just changed my delegate from weak reference to strong, that's it.

    Might be The issue was, when one of delegate method got called then delegate object was becoming nil, as it was weak reference.