我在 swift 中尝试 objective-c 等效块时遇到问题

I'm having trouble with my attempt of objective-c block equivalent in swift

这是 objective-c 代码:

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!");
            }
        }

这是一个错误:

'(MDCPanState) -> (MDCPanState) -> $T2' 不可转换为 'MDCPanState'

非常感谢您的帮助。

我不是 100%,因为我现在附近没有 XCode,但我相信你需要改变这个:

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

对此:

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