From 46d982d4dff9124125eb01f0c92a01b1ba226ec2 Mon Sep 17 00:00:00 2001 From: Shane Cowherd Date: Fri, 5 Jan 2018 08:29:49 -0700 Subject: [PATCH] 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)?