我们在objective-c中有一个方法,我们想要快速,我们已经完成了大部分方法的任务,但仍然坚持如何处理空洞。快速代码如下:
extension PMKPromise {
private func objCBlockFromPromiseClosure(closure: (AnyObject) -> (PMKPromise?)) -> AnyObject {
return unsafeBitCast(closure as @convention(block) (AnyObject) -> (PMKPromise?), AnyObject.self)
}
func swiftThen(closure: (AnyObject) -> (PMKPromise?)) -> PMKPromise {
return self.then()(objCBlockFromPromiseClosure(closure))
}
func swiftCatch(closure: (AnyObject) -> (PMKPromise?)) -> PMKPromise {
return self.catchOn()(dispatch_get_main_queue(), objCBlockFromPromiseClosure(closure))
}
}
上面的相应Objective-C代码在这里:
- (PMKPromise *(^)(id))then;
- (PMKPromise *(^)(dispatch_queue_t, id))catchOn;
我们需要帮助的方法是:
- (PMKPromise *(^)(void(^)(void)))finally;
创建一个新的swiftFinally(closure)函数是我们的目标,但我们不确定用于闭包或bitcast的类型。
谢谢。