不能在Swift 3.0中调用非函数类型'OnAckCallback'的值

时间:2021-12-19 18:03:45

in my Swift2 I had a function that worked:

在我的Swift2中,我有一个有效的功能:

func connectToServerWithNickname(_ nickname: String) {
    print("CONNECTING TO SOCKET SERVER \(nickname)")
    socket.emitWithAck("connectUser", nickname)(timeoutAfter: 3) { data in
        print("CONNECTED FOR SURE")
    }
}

but when I moved my whole code to Swift3, I'm getting error:

但当我将整个代码移动到Swift3时,我收到错误:

cannot call value of non-function type 'OnAckCallback'

不能在Swift 3.0中调用非函数类型'OnAckCallback'的值

That method comes from the socket.io library and it looks there like this:

该方法来自socket.io库,它看起来像这样:

/// Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
/// an ack.
public func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback {
    return emitWithAck(event, with: items)
}
/// Same as emitWithAck, but for Objective-C
public func emitWithAck(_ event: String, with items: [Any]) -> OnAckCallback {
    return createOnAck([event] + items)
}

private func createOnAck(_ items: [Any]) -> OnAckCallback {
    currentAck += 1

    return OnAckCallback(ackNumber: currentAck, items: items, socket: self)
}

how can I fix my code so that it compiles?

如何修复我的代码以便编译?

1 个解决方案

#1


2  

I ran into the same issue after updating to Socket.IO-client-swift 8.2.0. Here is the change you need to make.

在更新到Socket.IO-client-swift 8.2.0后,我遇到了同样的问题。以下是您需要进行的更改。

Working Code

工作守则

socket.emitWithAck("connectUser", nickname).timingOut(after: 3, callback: { data in
    print("CONNECTED FOR SURE")
})


Previous Code, causing error

以前的代码,导致错误

socket.emitWithAck("connectUser", nickname)(timeoutAfter: 3) { data in
    print("CONNECTED FOR SURE")
}

#1


2  

I ran into the same issue after updating to Socket.IO-client-swift 8.2.0. Here is the change you need to make.

在更新到Socket.IO-client-swift 8.2.0后,我遇到了同样的问题。以下是您需要进行的更改。

Working Code

工作守则

socket.emitWithAck("connectUser", nickname).timingOut(after: 3, callback: { data in
    print("CONNECTED FOR SURE")
})


Previous Code, causing error

以前的代码,导致错误

socket.emitWithAck("connectUser", nickname)(timeoutAfter: 3) { data in
    print("CONNECTED FOR SURE")
}