0

Here is the objective-c code:

options.onPan = ^(MDCPanState *state){
    if (state.thresholdRatio == 1.f && state.direction == MDCSwipeDirectionLeft) {
        NSLog(@"Let go now to delete the photo!");
    }
};

Swift:

   var options = MDCSwipeToChooseViewOptions()
        options.delegate = self
        options.likedText = "Keep"
        options.likedColor = UIColor.blueColor()
        options.nopeText = "Delete"

        options.onPan = { (state: MDCPanState) in
            if state.thresholdRatio == 1.0 && state.direction == MDCSwipeDirection.Left {
                println("Let go now to delete the photo!");
            }
        }

This is throwing an error:

'(MDCPanState) -> (MDCPanState) -> $T2' is not convertible to 'MDCPanState'

Would appreciate some help thanks.

3
  • What is the type declaration of options.onPan? The implication of the error message seems to be that the closure needs to return non void. Commented Mar 3, 2015 at 16:44
  • Also, is there an = sign missing in the Swift example? Commented Mar 3, 2015 at 16:45
  • @JeremyP I've updated my answer. The return type is MDCSwipeToChooseViewOptions() Commented Mar 3, 2015 at 17:14

1 Answer 1

1

I'm not 100% since I don't have XCode near me at the moment, but I believe you need to change this:

options.onPan = { (state: MDCPanState) in
        if state.thresholdRatio == 1.0 && state.direction == MDCSwipeDirection.Left {
            println("Let go now to delete the photo!");
        }

to this:

options.onPan = { (state: MDCPanState!) -> Void in
        if state.thresholdRatio == 1.0 && state.direction == MDCSwipeDirection.Left {
            println("Let go now to delete the photo!");
        }
Sign up to request clarification or add additional context in comments.

3 Comments

What's weird about the syntax to you?
Its seeing the { after the equals sign. I haven't seen this construct before. Can you provide more information or a link to some docs to help understand it? Is it shortened notation?
you are setting onPan to a completion block and that's the syntax in swift. this may help codefellows.org/blog/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.