Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define the custom UIGestureRecognizer in Swift?

I want to define the custom UIGestureRecognizer in Swift, but I cannot import UIGestureRecognizerSubclass and cannot override the methods of "touchesBegan", "touchesMoved", and so on.

"UIGestureRecognizerSubclass.h" is in the UIKit module, but only modules can likely be imported in Swift and header files cannot be imported.

How can I import UIGestureRecognizerSubclass and define the custom UIGestureRecognizer?


Edit:

I added the below code in Bridging-Header.h and I successfully compiled my custom gesture recognizer.

#import <UIKit/UIGestureRecognizerSubclass.h>

But this code may import "UIGestureRecognizerSubclass.h" for every swift files in my project, so I am thinking it is not the best way.

Is it right way? Is there another proper solution?

like image 753
polikeiji Avatar asked Jun 10 '14 10:06

polikeiji


Video Answer


1 Answers

You need to add the import:

import UIKit.UIGestureRecognizerSubclass

as in:

import UIKit
import UIKit.UIGestureRecognizerSubclass
like image 193
Chris Conover Avatar answered Nov 15 '22 07:11

Chris Conover