Move helper method
This commit is contained in:
parent
ddd7003d89
commit
64b9774c83
@ -140,7 +140,7 @@ class SocketSideEffectTest: XCTestCase {
|
|||||||
func testSocketDataToAnyObject() {
|
func testSocketDataToAnyObject() {
|
||||||
let data = ["test", 1, 2.2, ["Hello": 2, "bob": 2.2], true, [1, 2], [1.1, 2]] as [SocketData]
|
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() {
|
func testHandleMultipleBinaryEvent() {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public final class SocketAckEmitter : NSObject {
|
|||||||
public func with(_ items: SocketData...) {
|
public func with(_ items: SocketData...) {
|
||||||
guard ackNum != -1 else { return }
|
guard ackNum != -1 else { return }
|
||||||
|
|
||||||
socket.emitAck(ackNum, with: socket.socketDataToAnyObject(items))
|
socket.emitAck(ackNum, with: items.toAnyObjectArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
public func with(_ items: [AnyObject]) {
|
public func with(_ items: [AnyObject]) {
|
||||||
|
|||||||
@ -29,6 +29,13 @@ enum JSONError : Error {
|
|||||||
case notNSDictionary
|
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 {
|
extension Array where Element: AnyObject {
|
||||||
func toJSON() throws -> Data {
|
func toJSON() throws -> Data {
|
||||||
return try JSONSerialization.data(withJSONObject: self as NSArray, options: JSONSerialization.WritingOptions(rawValue: 0))
|
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
|
/// Send a message to the server
|
||||||
public func emit(_ event: String, _ items: SocketData...) {
|
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
|
/// 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
|
/// Sends a message to the server, requesting an ack. Use the onAck method of SocketAckHandler to add
|
||||||
/// an ack.
|
/// an ack.
|
||||||
public func emitWithAck(_ event: String, _ items: SocketData...) -> OnAckCallback {
|
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
|
/// Same as emitWithAck, but for Objective-C
|
||||||
@ -411,11 +411,6 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable
|
|||||||
handlers.removeAll(keepingCapacity: false)
|
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) {
|
private func tryReconnect(reason: String) {
|
||||||
guard reconnecting else { return }
|
guard reconnecting else { return }
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user