diff --git a/SocketIO-iOSTests/SocketTestCases.swift b/SocketIO-iOSTests/SocketTestCases.swift index b090e7d..da5277c 100644 --- a/SocketIO-iOSTests/SocketTestCases.swift +++ b/SocketIO-iOSTests/SocketTestCases.swift @@ -111,6 +111,8 @@ class SocketTestCases: NSObject { static func testJSONWithBuffer(abstractSocketSend:SocketSendFunction) { let testName = "testJSONWithBuffer" + let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)! + func didGetResult(result:NSArray?, ack:AckEmitter?) { if let json = result?.firstObject as? NSDictionary { XCTAssertEqual((json.valueForKey("testString")! as! String), "test") @@ -123,7 +125,7 @@ class SocketTestCases: NSObject { XCTFail("Should have NSDictionary as result") } } - let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15] + let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15, "buf": data] abstractSocketSend(testName: testName, emitData: json, callback: didGetResult) } diff --git a/SocketIOClientSwift/SocketPacket.swift b/SocketIOClientSwift/SocketPacket.swift index ee648fc..3f65d4a 100644 --- a/SocketIOClientSwift/SocketPacket.swift +++ b/SocketIOClientSwift/SocketPacket.swift @@ -281,12 +281,14 @@ private extension SocketPacket { } return arr - } else if let dict = data as? NSMutableDictionary { + } else if let dict = data as? NSDictionary { + let mutDict = NSMutableDictionary(dictionary: dict) + for (key, value) in dict { - dict[key as! NSCopying] = shred(value, binary: &binary) + mutDict[key as! NSCopying] = shred(value, binary: &binary) } - return dict + return mutDict } else { return data }