【发布时间】:2017-03-20 12:42:03
【问题描述】:
我的 swift 项目中有一个第三方 Objective-C 库,在其中一个 .h 文件中,它有一个 typedef:
typedef void (^YDBlutoothToolContectedList) (NSArray *);
在类内部,它有一个属性:
@property (nonatomic, copy) YDBlutoothToolContectedList blutoothToolContectedList;
(请忽略其拼写)
当我尝试在我的 swift 类中使用此属性时,我使用
bt.blutoothToolContectedList = {(_ tempArray: [Any]) -> Void in
self.devices = tempArray
self.tableView.reloadData()
}
我得到错误说:
Cannot assign value of type '([Any]) -> Void' to type 'YDBlutoothToolContectedList!'
我知道上面的 swift 中的 Objective-C 代码是:
typealias YDBlutoothToolContectedList = () -> Void
但是我不能重写那个Objective-C文件并且swift不能强制转换闭包类型,有没有办法解决这个问题?
【问题讨论】:
标签: ios objective-c swift closures objective-c-blocks