为什么Swift不能编译我的回调?

时间:2018-03-09 15:09:01

标签: swift

我在尝试编译我的一个viewController时面临一个奇怪的错误,这个viewController使用如下定义的函数beginGravityVectorUpdates

 public func beginGravityVectorUpdates(withCompletionHandler aHandler: CompletionCallback?, andNotificationHandler aNotificationHandler: GravityVectorNotificationCallback?) {

 var accGravityVector : Array<Float32>

//assume that accGravityVector is here filled with data that is right 

 aNotificationHandler?(self.getComponent(component: "X",inputXYZVector: accGravityVector),accGravityVector[1],accGravityVector[2])

}

    func getComponent(component: String,inputXYZVector: Array<Float32>) -> Array<Float32> {
        var accComponent : Array<Float32> = Array()
        var indx : Int = 0

        switch(component){
        case "X":
            indx = 0;
            break
        case "Y":
            indx = 1;
            break
        case "Z":
            indx = 2;
            break
        default:
            debugPrint("Unknonw component to get->\(component)")
        }

        for iAcc in stride(from: indx, to: inputXYZVector.count, by: 3) {
            accComponent[iAcc] = inputXYZVector[iAcc]
        }
        return accComponent
    }

是我GravityVectorNotificationCallback

的定义
public typealias GravityVectorNotificationCallback  = (_ x: Array<Float32>,_  y: Float, _ z: Float) -> (Void)

当我因某种原因尝试编译它时,编译器会使用beginGravityVectorUpdates来编译使用Array<Float32>的viewController进行编译,相反,如果我将GravityVectorNotificationCallbackFloat的使用更改为单个<span id="FormAssistStatus">On</span> (作为其他两个组件)编译器经历,只需2分钟即可编译。提到我想返回一个数组,而不是只返回一个当前值

为什么会这样?我做错了什么?

提前致谢

0 个答案:

没有答案