From 4ca2710faab3a60b73995ecc75c0e834a484983b Mon Sep 17 00:00:00 2001 From: Dmitry Preobrazhenskiy Date: Thu, 15 Nov 2018 23:26:01 +0300 Subject: [PATCH 1/4] Convert to Swift 4.2 --- Socket.IO-Client-Swift.xcodeproj/project.pbxproj | 6 +++--- Source/SocketEngine.swift | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index feaabdd..22fd0f0 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -537,7 +537,7 @@ TargetAttributes = { 572EF2181B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; - LastSwiftMigration = 0920; + LastSwiftMigration = 1010; }; 572EF2231B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; @@ -889,7 +889,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -941,7 +941,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index 0c87622..dea3b48 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -226,7 +226,8 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll private func handleBase64(message: String) { // binary in base64 string let noPrefix = String(message[message.index(message.startIndex, offsetBy: 2).. Date: Wed, 28 Nov 2018 22:29:20 +0200 Subject: [PATCH 2/4] Fix failing tests This is achieved by adding sorted keys with iOS 11 to the JSONSerialization which should produce the outcome string sorted --- SocketIO-MacTests/SocketBasicPacketTest.swift | 8 ++++---- SocketIO-MacTests/SocketNamespacePacketTest.swift | 8 ++++---- Source/SocketExtensions.swift | 6 +++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/SocketIO-MacTests/SocketBasicPacketTest.swift b/SocketIO-MacTests/SocketBasicPacketTest.swift index d2614fb..5a61e44 100644 --- a/SocketIO-MacTests/SocketBasicPacketTest.swift +++ b/SocketIO-MacTests/SocketBasicPacketTest.swift @@ -46,7 +46,7 @@ class SocketBasicPacketTest: XCTestCase { } func testJSONEmit() { - let expectedSendString = "2[\"test\",{\"null\":null,\"hello\":1,\"test\":\"hello\",\"foobar\":true}]" + let expectedSendString = "2[\"test\",{\"foobar\":true,\"hello\":1,\"null\":null,\"test\":\"hello\"}]" let sendData: [Any] = ["test", ["foobar": true, "hello": 1, "test": "hello", "null": NSNull()]] let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false) @@ -71,7 +71,7 @@ class SocketBasicPacketTest: XCTestCase { } func testMultipleBinaryEmit() { - let expectedSendString = "52-[\"test\",{\"data2\":{\"_placeholder\":true,\"num\":0},\"data1\":{\"_placeholder\":true,\"num\":1}}]" + let expectedSendString = "52-[\"test\",{\"data1\":{\"_placeholder\":true,\"num\":1},\"data2\":{\"_placeholder\":true,\"num\":0}}]" let sendData: [Any] = ["test", ["data1": data, "data2": data2] as NSDictionary] let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/", ack: false) @@ -123,7 +123,7 @@ class SocketBasicPacketTest: XCTestCase { } func testJSONAck() { - let expectedSendString = "30[{\"null\":null,\"hello\":1,\"test\":\"hello\",\"foobar\":true}]" + let expectedSendString = "30[{\"foobar\":true,\"hello\":1,\"null\":null,\"test\":\"hello\"}]" let sendData = [["foobar": true, "hello": 1, "test": "hello", "null": NSNull()]] let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true) @@ -140,7 +140,7 @@ class SocketBasicPacketTest: XCTestCase { } func testMultipleBinaryAck() { - let expectedSendString = "62-0[{\"data2\":{\"_placeholder\":true,\"num\":0},\"data1\":{\"_placeholder\":true,\"num\":1}}]" + let expectedSendString = "62-0[{\"data1\":{\"_placeholder\":true,\"num\":1},\"data2\":{\"_placeholder\":true,\"num\":0}}]" let sendData = [["data1": data, "data2": data2]] let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/", ack: true) diff --git a/SocketIO-MacTests/SocketNamespacePacketTest.swift b/SocketIO-MacTests/SocketNamespacePacketTest.swift index 51a7ba4..079c904 100644 --- a/SocketIO-MacTests/SocketNamespacePacketTest.swift +++ b/SocketIO-MacTests/SocketNamespacePacketTest.swift @@ -38,7 +38,7 @@ class SocketNamespacePacketTest: XCTestCase { } func testJSONEmit() { - let expectedSendString = "2/swift,[\"test\",{\"null\":null,\"test\":\"hello\",\"hello\":1,\"foobar\":true}]" + let expectedSendString = "2/swift,[\"test\",{\"foobar\":true,\"hello\":1,\"null\":null,\"test\":\"hello\"}]" let sendData: [Any] = ["test", ["foobar": true, "hello": 1, "test": "hello", "null": NSNull()] as NSDictionary] let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/swift", ack: false) @@ -64,7 +64,7 @@ class SocketNamespacePacketTest: XCTestCase { } func testMultipleBinaryEmit() { - let expectedSendString = "52-/swift,[\"test\",{\"data2\":{\"_placeholder\":true,\"num\":0},\"data1\":{\"_placeholder\":true,\"num\":1}}]" + let expectedSendString = "52-/swift,[\"test\",{\"data1\":{\"_placeholder\":true,\"num\":1},\"data2\":{\"_placeholder\":true,\"num\":0}}]" let sendData: [Any] = ["test", ["data1": data, "data2": data2] as NSDictionary] let packet = SocketPacket.packetFromEmit(sendData, id: -1, nsp: "/swift", ack: false) @@ -114,7 +114,7 @@ class SocketNamespacePacketTest: XCTestCase { } func testJSONAck() { - let expectedSendString = "3/swift,0[{\"null\":null,\"hello\":1,\"test\":\"hello\",\"foobar\":true}]" + let expectedSendString = "3/swift,0[{\"foobar\":true,\"hello\":1,\"null\":null,\"test\":\"hello\"}]" let sendData = [["foobar": true, "hello": 1, "test": "hello", "null": NSNull()]] let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/swift", ack: true) @@ -131,7 +131,7 @@ class SocketNamespacePacketTest: XCTestCase { } func testMultipleBinaryAck() { - let expectedSendString = "62-/swift,0[{\"data2\":{\"_placeholder\":true,\"num\":0},\"data1\":{\"_placeholder\":true,\"num\":1}}]" + let expectedSendString = "62-/swift,0[{\"data1\":{\"_placeholder\":true,\"num\":1},\"data2\":{\"_placeholder\":true,\"num\":0}}]" let sendData = [["data1": data, "data2": data2]] let packet = SocketPacket.packetFromEmit(sendData, id: 0, nsp: "/swift", ack: true) diff --git a/Source/SocketExtensions.swift b/Source/SocketExtensions.swift index bf5280a..675625f 100644 --- a/Source/SocketExtensions.swift +++ b/Source/SocketExtensions.swift @@ -31,7 +31,11 @@ enum JSONError : Error { extension Array { func toJSON() throws -> Data { - return try JSONSerialization.data(withJSONObject: self, options: JSONSerialization.WritingOptions(rawValue: 0)) + if #available(iOSApplicationExtension 11.0, *) { + return try JSONSerialization.data(withJSONObject: self, options: [.sortedKeys]) + } else { + return try JSONSerialization.data(withJSONObject: self, options: JSONSerialization.WritingOptions(rawValue: 0)) + } } } From c0a4273d5b023caae3a8a265ca5ab75b8d2cf200 Mon Sep 17 00:00:00 2001 From: Dmitry Preobrazhenskiy Date: Wed, 28 Nov 2018 22:39:53 +0200 Subject: [PATCH 3/4] fixup! Fix failing tests --- Source/SocketExtensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SocketExtensions.swift b/Source/SocketExtensions.swift index 675625f..aa83b58 100644 --- a/Source/SocketExtensions.swift +++ b/Source/SocketExtensions.swift @@ -31,7 +31,7 @@ enum JSONError : Error { extension Array { func toJSON() throws -> Data { - if #available(iOSApplicationExtension 11.0, *) { + if #available(iOS 11.0, OSX 10.13, tvOS 11.0, *) { return try JSONSerialization.data(withJSONObject: self, options: [.sortedKeys]) } else { return try JSONSerialization.data(withJSONObject: self, options: JSONSerialization.WritingOptions(rawValue: 0)) From 4af28c3a576d441376ebc20bb47ffe929cc1d20d Mon Sep 17 00:00:00 2001 From: Dmitry Preobrazhenskiy Date: Wed, 28 Nov 2018 23:09:36 +0200 Subject: [PATCH 4/4] Update podspec Remove the swift version and update podspec to include Swift 4.2 Fixes https://github.com/socketio/socket.io-client-swift/issues/1101 --- .swift-version | 1 - Socket.IO-Client-Swift.podspec | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 .swift-version diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 8c50098..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -3.1 diff --git a/Socket.IO-Client-Swift.podspec b/Socket.IO-Client-Swift.podspec index a676a7e..6c0adf2 100644 --- a/Socket.IO-Client-Swift.podspec +++ b/Socket.IO-Client-Swift.podspec @@ -17,6 +17,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v9.0.1' } s.source_files = "Source/**/*.swift" s.requires_arc = true - s.pod_target_xcconfig = {'SWIFT_VERSION' => '3.1'} + s.swift_version = "4.2" + # s.dependency 'Starscream', '~> 0.9' # currently this repo includes Starscream swift files end