Importing an objc control into Swift: Error when putting an action (func) of my contole

Asked

Viewed 51 times

2

I decided to make an app in Swift this time, and as usual I use my custom control (Menuview). In objc I know how it works and everything worked, in Swift I followed all the steps, import in bridging-header. h, and put the Menuviewdelegate I created too.

So far so good, no mistake Codigo swift importando o controle MenuView When I put the command I created in control

func MenuView(MenuView: MenuView!, didTouch sender: UIPanGestureRecognizer!) {

}

appeared the following error:(Use of undeclared type 'Menuview') pointing out all lines that contained the object of "Menuview" Codigo swift importando o controle com erro

How do I fix this ?? I did something wrong, forgot something... Thanks in advance for some help.

1 answer

4


There is a conflict between the class name MenuView and the signature of the delegate method which also calls MenuView. In Objective-C, the signature of the method is MenuView:didTouch, but in Swift he’s just MenuView and Gesture Sender does not appear in the name.

In this case, so that there is no conflict, following the Cocoa design the method name should be - (void)menuView:(MenuView *)menuView didTouch:(UIPanGestureRecognizer *)sender;

  • In fact, the error is gone. But when this action is started the error app on line 14 (fatal error). What can be ??

  • I don’t understand your doubt. The app will break for sure because that’s what line 14 does. If you remove the init that is breaking (line 13 to 15) will not break anymore.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.