IOS迅速属性块设置和获取
问题描述:
在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。
答
@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)
}
https://*.com/questions/24196938/ios-swift-pass-作为财产封闭? – Larme
你有设置和访问反向。 –