Tolgay Toklar Tolgay Toklar - 1 month ago 26
Swift Question

Binary operators with Swift 3

I am switching to Swift 3 and i am getting following compiler error for this line:

if cma.socket.status != .Connected {
cma.socket.connect()
print("connect");
}else{
cma.socket.reconnect()
print("reconnect")
}



Binary operator '!=' cannot be applied to operands of type
'SocketIOClientStatus' and '_'


I found this question: Swift 3.0 binary operator '==' cannot be applied but still don't know how to fix it.

How can I resolve this problem?

Answer

The enum is defined as:

@objc public enum SocketIOClientStatus : Int {
    case notConnected, disconnected, connecting, connected
}

This means your code needs a small change (pun intended):

if cm.socket.status != .connected {