如何在Swift 3中输入typealias方法?

时间:2016-10-17 13:14:28

标签: swift swift3 type-alias

我正在尝试将我的Swift 2+代码转换为Swift 3.我有一些typealias代码引用,我无法根据Swift 3语法要求修复它。

typealias UpdateProcessHandler = (_ value:Double) -> Void

class StartUploadingProcess: Operation
{
    ...
    fileprivate var updateHandler: UpdateProcessHandler!

    init(filePath: String, updateHandler:@escaping UpdateProcessHandler)
    {
        self.updateHandler = updateHandler
        ...
    }

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
    {
        ...
        self.updateHandler(value: self.progress.fractionCompleted)
        ...
    }
}

当我尝试调用方法self.updateHandler时,XCode报告编译器错误:Cannot call value of non-function type 'UpdateProcessHandler!'

为什么我有这个或如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

self.updateHandler(self.progress.fractionCompleted)