Cyupa
Cyupa

Reputation: 1135

Cannot use unwind segue defined in Objective-C used in Swift

I have a modal view controller that's inside a navigation controller that I present from diffent controllers and based on diferrent contexts it should return to a diffrent controllers.

Basically, whoever implements the segue identifer should probably be the point of return for this flow.

I have the following flow that present modally this entire flow:

A (Objective-C) -> B (Objective-C) -> C (Swift) -> D (Swift)

A, B and C implement the same segue method.

Class A and B implement the Objective-C version:

- (IBAction)unwindToRootTabBarViewController:(UIStoryboardSegue *)unwindSegue {}

while class C implemnts the Swift version:

override func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, withSender sender: Any) -> Bool {
        return true
}

@IBAction public func unwindToRootTabBarViewController(segue: UIStoryboardSegue) {}

When trying to unwind to the C Class that is written in Objective-C it crashed because I cannot find the method, even though it's there:

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[App.ClassCViewController unwindToRootTabBarViewController:]: unrecognized selector sent to instance 0x7ff035c634b0'

Any ideas why this might be happening?

Upvotes: 1

Views: 150

Answers (1)

Cyupa
Cyupa

Reputation: 1135

I gave it a little thought and changed the parameter type to the method from:

@IBAction public func unwindToRootTabBarViewController(segue: UIStoryboardSegue){}

to

@IBAction public func unwindToRootTabBarViewController(_: UIStoryboardSegue){}

And it worked!

I think it has to do with the way Swift and Objective-C deal with method signatures.

Upvotes: 1

Related Questions