2017-06-16 47 views
0

在Objective-C,我們做IOS迅速屬性塊設置和獲取

@property (strong, nonatomic) void(^Name)(id input, id selectedListItem); 

然後我們設置屬性

if (self.Name) { 
    self.Name(self,nil); 
} 

來訪問這個視圖 - 控制

[classObject setName:^(id input, id selectedListItem) 
// do something with the input and selectedListItem 
]; 

我們如何能做到這一點在swift3。

+0

https://stackoverflow.com/questions/24196938/ios-swift-pass-作爲財產封閉? – Larme

+0

你有設置和訪問反向。 –

回答

0
@property (strong, nonatomic) void(^Name)(id input, id selectedListItem); 

var name: ((input: Any, selectedListItem: Any?) ->())? = nil 

設置是

obj.name = { (input, selectedListItem) in 
    // do something with the input and selectedListItem 
} 

呼叫是

if let name = obj.name { 
    name(self, nil) 
}