0

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:

  • Just one ViewController and one button with IBAction connected.

Now:

  • In viewDidAppear I have initialized my framework and set delegate to self.
  • Once I get initialized successful delegate called, I call another method.
  • but the strange behaviour is everything stopped, even IBAction is not working.

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

Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130
  • 1
    Without seeing the MySDK side of this, there's not much to go on. – Avi Jan 12 '16 at 14:14
  • @Avi, The issue is only with delegate, when none of `delegate` called then `IBAction` is getting called, but when any of `delegate` called then nothing working. Might be issue of background thread etc... – Mohammad Zaid Pathan Jan 12 '16 at 14:17
  • It might be a lot of things. That's the point -- without source, we can't hope to help except by luck. – Avi Jan 12 '16 at 14:20
  • :(, I see, But it is very strange...The same thing is working if I only use my .h,.m files, but not working in .framework. – Mohammad Zaid Pathan Jan 12 '16 at 14:28

1 Answers1

2

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.

Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130