2015-01-13 52 views
-3

我正在使用自定義UISwitch控件,名爲DVSwitch,它是針對Swift/Xcode6項目編寫的Objective-C中編寫的。我需要調用-setPressedHandler:方法,並且很難將其轉換爲Swift。任何人都可以告訴我如何在Swift中編寫下面的代碼塊。將Objective-C方法轉換爲Swift

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

[Swift中Block的語法]的可能重複(http://stackoverflow.com/questions/24038713/syntax-of-block-in-swift) – Larme

回答

1

這將是:

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

很明顯,你必須在該項目的橋接報相應的該DVswitch頭。