将Objective-C方法转换为Swift

时间:2015-01-13 13:54:50

标签: ios objective-c swift

我正在使用名为DVSwitch的自定义UISwitch控件,该控件是用Objective-C编写的,用于Swift / Xcode6项目。我需要调用它的-setPressedHandler:方法并且很难将它转换为Swift。任何人都可以告诉我如何在Swift中编写下面的代码块。

[switcher setPressedHandler: ^(NSUInteger index) {
    NSLog(@"Did switch to index: %lu", (unsigned long)index);
}];

1 个答案:

答案 0 :(得分:1)

这将是:

switcher.setPressedHandler() { index in
    println("Did switch to index: \(index)")
}

显然,您必须在项目的桥接标题中包含相应的DVSwitch标题。