2016-11-04 52 views
2

調用非功能型的價值「OnAckCallback」我有工作的函數:不能在我的<code>Swift2</code>在雨燕3.0

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

,但是,當我提出我的整個代碼Swift3,我得到錯誤:

cannot call value of non-function type 'OnAckCallback' 

enter image description here

這種方法來自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) 
} 

我該如何修復我的代碼才能編譯?

回答

2

更新到後,我遇到了同樣的問題Socket.IO-client-swift 8.2.0。這是你需要做的改變。

工作守則

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


以前的代碼,從而導致錯誤

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