【问题标题】:ios swift property block setting and gettingios swift属性块设置与获取
【发布时间】:2017-11-19 06:13:25
【问题描述】:

在objective-c中我们这样做

@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 中做到这一点。

【问题讨论】:

标签: swift swift3 ios10 ios10.3.2


【解决方案1】:
@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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    相关资源
    最近更新 更多