From 46d982d4dff9124125eb01f0c92a01b1ba226ec2 Mon Sep 17 00:00:00 2001 From: Shane Cowherd Date: Fri, 5 Jan 2018 08:29:49 -0700 Subject: [PATCH 1/2] Migrated the Socket.IO 1.X build to Swift 4 --- .../project.pbxproj | 12 +++++++++-- Source/SocketEngine.swift | 7 +++---- Source/SocketEnginePollable.swift | 4 ++-- Source/SocketParsable.swift | 4 ++-- Source/SocketStringReader.swift | 21 +++++++++---------- Source/WebSocket.swift | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index de5755c..809a0de 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -537,9 +537,11 @@ TargetAttributes = { 572EF2181B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 0920; }; 572EF2231B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 0920; }; 572EF2371B51F18A00EEBB58 = { CreatedOnToolsVersion = 6.4; @@ -886,7 +888,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -937,7 +940,8 @@ PRODUCT_BUNDLE_IDENTIFIER = io.socket.SocketIOClientSwift; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -993,6 +997,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1037,6 +1043,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index c3114d1..8f9a85b 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -225,8 +225,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll private func handleBase64(message: String) { // binary in base64 string - let noPrefix = message[message.index(message.startIndex, offsetBy: 2).. String.Index { - currentIndex = message.characters.index(currentIndex, offsetBy: by) + currentIndex = message.index(currentIndex, offsetBy: by) return currentIndex } mutating func read(count: Int) -> String { - let readString = message[currentIndex.. String { - let substring = message[currentIndex.. String { - return read(count: message.characters.distance(from: currentIndex, to: message.endIndex)) + return read(count: message.distance(from: currentIndex, to: message.endIndex)) } } diff --git a/Source/WebSocket.swift b/Source/WebSocket.swift index 34152af..f57ec3d 100644 --- a/Source/WebSocket.swift +++ b/Source/WebSocket.swift @@ -115,7 +115,7 @@ open class WebSocket : NSObject, StreamDelegate { // MARK: - Block based API. - public var onConnect: ((Void) -> Void)? + public var onConnect: (() -> Void)? public var onDisconnect: ((NSError?) -> Void)? public var onText: ((String) -> Void)? public var onData: ((Data) -> Void)? From d3aaaec9bb2983b23eb440f42558b4f44fd1975e Mon Sep 17 00:00:00 2001 From: Shane Cowherd Date: Mon, 8 Jan 2018 11:22:09 -0700 Subject: [PATCH 2/2] Updated Project Swift variable to 4.0 Fixed handleOpen(openData) bug that was not covered in the unit tests. --- Socket.IO-Client-Swift.xcodeproj/project.pbxproj | 6 ++++-- Source/SocketEngine.swift | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 809a0de..feaabdd 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -1102,7 +1102,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1154,7 +1154,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.socket.$(PRODUCT_NAME:rfc1034identifier)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1313,6 +1313,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1364,6 +1365,7 @@ PRODUCT_NAME = SocketIO; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; diff --git a/Source/SocketEngine.swift b/Source/SocketEngine.swift index 8f9a85b..0c87622 100644 --- a/Source/SocketEngine.swift +++ b/Source/SocketEngine.swift @@ -540,7 +540,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll case .pong: handlePong(with: fixedString) case .open: - handleOpen(openData: fixedString) + handleOpen(openData: String(fixedString.dropFirst())) case .close: handleClose(fixedString) default: