Move helper method
This commit is contained in:
parent
ddd7003d89
commit
64b9774c83
@ -140,7 +140,7 @@ class SocketSideEffectTest: XCTestCase {
|
||||
func testSocketDataToAnyObject() {
|
||||
let data = ["test", 1, 2.2, ["Hello": 2, "bob": 2.2], true, [1, 2], [1.1, 2]] as [SocketData]
|
||||
|
||||
XCTAssertEqual(data.count, socket.socketDataToAnyObject(data).count)
|
||||
XCTAssertEqual(data.count, data.toAnyObjectArray().count)
|
||||
}
|
||||
|
||||
func testHandleMultipleBinaryEvent() {
|
||||
|
||||
@ -36,7 +36,7 @@ public final class SocketAckEmitter : NSObject {
|
||||
public func with(_ items: SocketData...) {
|
||||
guard ackNum != -1 else { return }
|
||||
|
||||
socket.emitAck(ackNum, with: socket.socketDataToAnyObject(items))
|
||||
socket.emitAck(ackNum, with: items.toAnyObjectArray())
|
||||
}
|
||||
|
||||
public func with(_ items: [AnyObject]) {
|
||||
|
||||
@ -29,6 +29,13 @@ enum JSONError : Error {
|
||||
case notNSDictionary
|
||||
}
|
||||
|
||||
extension Array {
|
||||
/// Because Swift 3 removes a lot of implicit briding so we have to perform more casts
|
||||
func toAnyObjectArray() -> [AnyObject] {
|
||||
return flatMap({$0 as? AnyObject})
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element: AnyObject {
|
||||
func toJSON() throws -> Data {
|
||||
return try JSONSerialization.data(withJSONObject: self as NSArray, options: JSONSerialization.WritingOptions(rawValue: 0))
|
||||
|
||||
@ -214,7 +214,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
||||
|
||||
/// Send a message to the server
|
||||
public func emit(_ event: String, _ items: SocketData...) {
|
||||
emit(event, with: socketDataToAnyObject(items))
|
||||
emit(event, with: items.toAnyObjectArray())
|
||||
}
|
||||
|
||||
/// Same as emit, but meant for Objective-C
|
||||
@ -230,7 +230,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
||||
/// 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: socketDataToAnyObject(items))
|
||||
return emitWithAck(event, with: items.toAnyObjectArray())
|
||||
}
|
||||
|
||||
/// Same as emitWithAck, but for Objective-C
|
||||
@ -410,11 +410,6 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
||||
public func removeAllHandlers() {
|
||||
handlers.removeAll(keepingCapacity: false)
|
||||
}
|
||||
|
||||
/// Because Swift 3 removes a lot of implicit briding so we have to perform more casts
|
||||
func socketDataToAnyObject(_ data: [SocketData]) -> [AnyObject] {
|
||||
return data.flatMap({$0 as? AnyObject})
|
||||
}
|
||||
|
||||
private func tryReconnect(reason: String) {
|
||||
guard reconnecting else { return }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user