简体   繁体   中英

Delegate methods in Objective-C and viewcontroller in Swift. How to call protocols? - iOS

I have view controller like in Swift:

class ViewController: UIViewController, DraggableViewDelegate {

(Type viewcontroller does not conform to protocol 'DraggableviewDelegate')

I knew that I have to take protocol methods from delegate class, but it was a in Objective-C like:

#import <UIKit/UIKit.h>
#import "OverlayView.h"

@protocol DraggableViewDelegate <NSObject>

-(void)cardSwipedLeft:(UIView *)card;
-(void)cardSwipedRight:(UIView *)card;

@end

@interface DraggableView : UIView

@property (weak) id <DraggableViewDelegate> delegate;

@property (nonatomic, strong)UIPanGestureRecognizer   *panGestureRecognizer;
@property (nonatomic)CGPoint originalPoint;
@property (nonatomic,strong)OverlayView* overlayView;
@property (nonatomic,strong)UILabel* information; 


-(void)leftClickAction;
-(void)rightClickAction;

@end

Here the methods are in Objective-C:

 -(void)method {}

But in Swift it takes:

func methodName(){}

Writing like a func card... its taking the delagate methods. like

-(void)cardSwipedLeft:(UIView *)card; as
func cardSwipedLeft.....

Thanks Doro and Dharmesh Kheni for solution and best tuitorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM