2017-06-16 23 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) 
}