Reputation: 31
I am trying to do a "Tinder Swipe" in Swift using MDCSwipeToChoose Delegate. I am following this tutorial https://github.com/modocache/MDCSwipeToChoose
But after installing the CocoaPod and inserting the code from the tutorial I get the error "Type 'ViewController' does not conform to protocol 'MDCSwipeToChooseDelegate'". Here is the part of the code in my ViewController that contains the error:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var options = MDCSwipeToChooseViewOptions() // Here is where I get the error
options.delegate = self //And the same error here
options.likedText = "Keep"
options.likedColor = UIColor.blueColor()
options.nopeText = "Delete"
options.onPan = { state -> Void in
if state.thresholdRatio == 1 && state.direction == MDCSwipeDirection.Left {
println("Photo deleted!")
}
}
var view = MDCSwipeToChooseView(frame: self.view.bounds, options: options)
view.imageView.image = UIImage(named: "photo.png")
self.view.addSubview(view)
}
Upvotes: 2
Views: 911
Reputation: 4879
Your ViewController should implement the MDCSwipeToChooseDelegate
protocol. So it should be like:
class ViewController: UIViewController, MDCSwipeToChooseDelegate {
And you might want to implement the methods of this protocol (there are optional but depending what you want to do, you may have to use them)
func viewDidCancelSwipe(view: UIView) -> Void
func view(view: UIView, shouldBeChosenWithDirection: MDCSwipeDirection) -> Bool
func view(view: UIView, wasChosenWithDirection: MDCSwipeDirection) -> Void
Upvotes: 2
Reputation: 11435
Did you implement all the necessary methods?
func viewDidCancelSwipe(view: UIView) -> Void
func view(view: UIView, shouldBeChosenWithDirection: MDCSwipeDirection) -> Bool
func view(view: UIView, wasChosenWithDirection: MDCSwipeDirection) -> Void
Upvotes: 0