From 7c3de9f30a8fddd5fb63a7c68e06e634d9078e56 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 15 Jun 2016 10:13:44 -0400 Subject: [PATCH] even more xcode 8 stuff. style changes --- .../project.pbxproj | 32 ++++++++++++++- .../xcschemes/SocketIO-Mac.xcscheme | 2 +- .../xcschemes/SocketIO-iOS.xcscheme | 2 +- .../xcschemes/SocketIO-tvOS.xcscheme | 2 +- SocketIO-MacTests/SocketObjectiveCTest.m | 2 +- SocketIO-MacTests/SocketParserTest.swift | 4 +- Source/SocketEngine.swift | 40 +++++++++---------- Source/SocketEngineClient.swift | 6 +-- Source/SocketEnginePollable.swift | 16 +++----- Source/SocketEngineSpec.swift | 4 +- Source/SocketIOClient.swift | 30 ++++++-------- Source/SocketIOClientSpec.swift | 6 +-- Source/SocketParsable.swift | 16 ++++---- Source/SocketStringReader.swift | 14 +++---- 14 files changed, 97 insertions(+), 79 deletions(-) diff --git a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj index 2403b7d..de9c093 100644 --- a/Socket.IO-Client-Swift.xcodeproj/project.pbxproj +++ b/Socket.IO-Client-Swift.xcodeproj/project.pbxproj @@ -526,7 +526,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; TargetAttributes = { 572EF2181B51F16C00EEBB58 = { CreatedOnToolsVersion = 6.4; @@ -799,10 +799,25 @@ isa = XCBuildConfiguration; buildSettings = { BITCODE_GENERATION_MODE = bitcode; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "Developer ID Application"; ENABLE_BITCODE = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; @@ -817,8 +832,23 @@ isa = XCBuildConfiguration; buildSettings = { BITCODE_GENERATION_MODE = bitcode; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "Developer ID Application"; ENABLE_BITCODE = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_NAME = SocketIOClientSwift; diff --git a/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme b/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme index 64047b1..c03a4b1 100644 --- a/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme +++ b/Socket.IO-Client-Swift.xcodeproj/xcshareddata/xcschemes/SocketIO-Mac.xcscheme @@ -1,6 +1,6 @@ (URL, URL) { @@ -273,20 +271,20 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe ws?.connect() } - public func didError(_ error: String) { - DefaultSocketLogger.Logger.error("%@", type: logType, args: error) - client?.engineDidError(error) - disconnect(error) + public func didError(reason: String) { + DefaultSocketLogger.Logger.error("%@", type: logType, args: reason) + client?.engineDidError(reason: reason) + disconnect(reason: reason) } - public func disconnect(_ reason: String) { + public func disconnect(reason: String) { guard connected else { return closeOutEngine() } DefaultSocketLogger.Logger.log("Engine is being closed.", type: logType) if closed { closeOutEngine() - client?.engineDidClose(reason) + client?.engineDidClose(reason: reason) return } @@ -352,7 +350,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe } private func handleClose(_ reason: String) { - client?.engineDidClose(reason) + client?.engineDidClose(reason: reason) } private func handleMessage(_ message: String) { @@ -395,10 +393,10 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe doPoll() } - client?.engineDidOpen("Connect") + client?.engineDidOpen(reason: "Connect") } } catch { - didError("Error parsing open packet") + didError(reason: "Error parsing open packet") } } @@ -478,7 +476,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe //Server is not responding if pongsMissed > pongsMissedMax { - client?.engineDidClose("Ping timeout") + client?.engineDidClose(reason: "Ping timeout") return } @@ -487,9 +485,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe write("", withType: .ping, withData: []) let time = DispatchTime.now() + Double(Int64(pingInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) - DispatchQueue.main.after(when: time) {[weak self] in - self?.sendPing() - } + DispatchQueue.main.after(when: time) {[weak self] in self?.sendPing() } } } @@ -539,7 +535,7 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe probing = false if closed { - client?.engineDidClose("Disconnect") + client?.engineDidClose(reason: "Disconnect") return } @@ -548,9 +544,9 @@ public final class SocketEngine : NSObject, SocketEnginePollable, SocketEngineWe websocket = false if let reason = error?.localizedDescription { - didError(reason) + didError(reason: reason) } else { - client?.engineDidClose("Socket Disconnected") + client?.engineDidClose(reason: "Socket Disconnected") } } else { flushProbeWait() diff --git a/Source/SocketEngineClient.swift b/Source/SocketEngineClient.swift index 8f77d51..49cac7c 100644 --- a/Source/SocketEngineClient.swift +++ b/Source/SocketEngineClient.swift @@ -26,9 +26,9 @@ import Foundation @objc public protocol SocketEngineClient { - func engineDidError(_ reason: String) - func engineDidClose(_ reason: String) - func engineDidOpen(_ reason: String) + func engineDidError(reason: String) + func engineDidClose(reason: String) + func engineDidOpen(reason: String) func parseEngineMessage(_ msg: String) func parseEngineBinaryData(_ data: Data) } diff --git a/Source/SocketEnginePollable.swift b/Source/SocketEnginePollable.swift index b0cc50b..b25686b 100644 --- a/Source/SocketEnginePollable.swift +++ b/Source/SocketEnginePollable.swift @@ -118,7 +118,7 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") if this.polling { - this.didError(err?.localizedDescription ?? "Error") + this.didError(reason: err?.localizedDescription ?? "Error") } return @@ -163,7 +163,7 @@ extension SocketEnginePollable { DefaultSocketLogger.Logger.error(err?.localizedDescription ?? "Error", type: "SocketEnginePolling") if this.polling { - this.didError(err?.localizedDescription ?? "Error") + this.didError(reason: err?.localizedDescription ?? "Error") } return @@ -186,16 +186,12 @@ extension SocketEnginePollable { var reader = SocketStringReader(message: str) while reader.hasNext { - if let n = Int(reader.readUntilStringOccurence(":")) { - let str = reader.read(n) + if let n = Int(reader.readUntilOccurence(of: ":")) { + let str = reader.read(count: n) - (handleQueue).async { - self.parseEngineMessage(str, fromPolling: true) - } + handleQueue.async { self.parseEngineMessage(str, fromPolling: true) } } else { - handleQueue.async { - self.parseEngineMessage(str, fromPolling: true) - } + handleQueue.async { self.parseEngineMessage(str, fromPolling: true) } break } } diff --git a/Source/SocketEngineSpec.swift b/Source/SocketEngineSpec.swift index d39d463..b83d480 100644 --- a/Source/SocketEngineSpec.swift +++ b/Source/SocketEngineSpec.swift @@ -51,8 +51,8 @@ import Foundation init(client: SocketEngineClient, url: URL, options: NSDictionary?) func connect() - func didError(_ error: String) - func disconnect(_ reason: String) + func didError(reason: String) + func disconnect(reason: String) func doFastUpgrade() func flushWaitingForPostToWebSocket() func parseEngineData(_ data: Data) diff --git a/Source/SocketIOClient.swift b/Source/SocketIOClient.swift index d56cfb0..48b3627 100644 --- a/Source/SocketIOClient.swift +++ b/Source/SocketIOClient.swift @@ -110,7 +110,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable deinit { DefaultSocketLogger.Logger.log("Client is being released", type: logType) - engine?.disconnect("Client Deinit") + engine?.disconnect(reason: "Client Deinit") } private func addEngine() -> SocketEngineSpec { @@ -150,7 +150,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable handleQueue.after(when: time) {[weak self] in if let this = self where this.status != .connected && this.status != .disconnected { this.status = .disconnected - this.engine?.disconnect("Connect timeout") + this.engine?.disconnect(reason: "Connect timeout") handler?() } @@ -185,7 +185,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable handleEvent("connect", data: [], isInternalMessage: false) } - func didDisconnect(_ reason: String) { + func didDisconnect(reason: String) { guard status != .disconnected else { return } DefaultSocketLogger.Logger.log("Disconnected: %@", type: logType, args: reason) @@ -193,7 +193,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable status = .disconnected // Make sure the engine is actually dead. - engine?.disconnect(reason) + engine?.disconnect(reason: reason) handleEvent("disconnect", data: [reason as AnyObject], isInternalMessage: true) } @@ -203,7 +203,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable DefaultSocketLogger.Logger.log("Closing socket", type: logType) - didDisconnect("Disconnect") + didDisconnect(reason: "Disconnect") } /// Send a message to the server @@ -262,7 +262,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable } } - public func engineDidClose(_ reason: String) { + public func engineDidClose(reason: String) { waitingPackets.removeAll() if status != .disconnected { @@ -270,7 +270,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable } if status == .disconnected || !reconnects { - didDisconnect(reason) + didDisconnect(reason: reason) } else if !reconnecting { reconnecting = true tryReconnect(reason) @@ -278,13 +278,13 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable } /// error - public func engineDidError(_ reason: String) { + public func engineDidError(reason: String) { DefaultSocketLogger.Logger.error("%@", type: logType, args: reason) handleEvent("error", data: [reason as AnyObject], isInternalMessage: true) } - public func engineDidOpen(_ reason: String) { + public func engineDidOpen(reason: String) { DefaultSocketLogger.Logger.log(reason, type: "SocketEngineClient") } @@ -383,22 +383,18 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable public func parseEngineMessage(_ msg: String) { DefaultSocketLogger.Logger.log("Should parse message: %@", type: "SocketIOClient", args: msg) - parseQueue.async { - self.parseSocketMessage(msg) - } + parseQueue.async { self.parseSocketMessage(msg) } } public func parseEngineBinaryData(_ data: Data) { - parseQueue.async { - self.parseBinaryData(data) - } + parseQueue.async { self.parseBinaryData(data) } } /// Tries to reconnect to the server. public func reconnect() { guard !reconnecting else { return } - engine?.disconnect("manual reconnect") + engine?.disconnect(reason: "manual reconnect") } /// Removes all handlers. @@ -426,7 +422,7 @@ public final class SocketIOClient : NSObject, SocketEngineClient, SocketParsable } if reconnectAttempts != -1 && currentReconnectAttempt + 1 > reconnectAttempts || !reconnects { - return didDisconnect("Reconnect Failed") + return didDisconnect(reason: "Reconnect Failed") } DefaultSocketLogger.Logger.log("Trying to reconnect", type: logType) diff --git a/Source/SocketIOClientSpec.swift b/Source/SocketIOClientSpec.swift index 183089e..1e2051c 100644 --- a/Source/SocketIOClientSpec.swift +++ b/Source/SocketIOClientSpec.swift @@ -27,15 +27,15 @@ protocol SocketIOClientSpec : class { var waitingPackets: [SocketPacket] { get set } func didConnect() - func didDisconnect(_ reason: String) - func didError(_ reason: String) + func didDisconnect(reason: String) + func didError(reason: String) func handleAck(_ ack: Int, data: [AnyObject]) func handleEvent(_ event: String, data: [AnyObject], isInternalMessage: Bool, withAck ack: Int) func joinNamespace(_ namespace: String) } extension SocketIOClientSpec { - func didError(_ reason: String) { + func didError(reason: String) { DefaultSocketLogger.Logger.error("%@", type: "SocketIOClient", args: reason) handleEvent("error", data: [reason as AnyObject], isInternalMessage: true, withAck: -1) diff --git a/Source/SocketParsable.swift b/Source/SocketParsable.swift index e3e66c5..5b32c10 100644 --- a/Source/SocketParsable.swift +++ b/Source/SocketParsable.swift @@ -53,7 +53,7 @@ extension SocketParsable { case .connect: handleConnect(pack) case .disconnect: - didDisconnect("Got Disconnect") + didDisconnect(reason: "Got Disconnect") case .error: handleEvent("error", data: pack.data, isInternalMessage: true, withAck: pack.id) default: @@ -65,7 +65,7 @@ extension SocketParsable { func parseString(_ message: String) -> Either { var parser = SocketStringReader(message: message) - guard let type = SocketPacket.PacketType(rawValue: Int(parser.read(1)) ?? -1) else { + guard let type = SocketPacket.PacketType(rawValue: Int(parser.read(count: 1)) ?? -1) else { return .left("Invalid packet type") } @@ -77,7 +77,7 @@ extension SocketParsable { var placeholders = -1 if type == .binaryEvent || type == .binaryAck { - if let holders = Int(parser.readUntilStringOccurence("-")) { + if let holders = Int(parser.readUntilOccurence(of: "-")) { placeholders = holders } else { return .left("Invalid packet") @@ -85,7 +85,7 @@ extension SocketParsable { } if parser.currentCharacter == "/" { - namespace = parser.readUntilStringOccurence(",") ?? parser.readUntilEnd() + namespace = parser.readUntilOccurence(of: ",") ?? parser.readUntilEnd() } if !parser.hasNext { @@ -95,19 +95,19 @@ extension SocketParsable { var idString = "" if type == .error { - parser.advance(-1) + parser.advance(by: -1) } else { while parser.hasNext { - if let int = Int(parser.read(1)) { + if let int = Int(parser.read(count: 1)) { idString += String(int) } else { - parser.advance(-2) + parser.advance(by: -2) break } } } - let d = message[parser.advance(1).. String.Index { + mutating func advance(by: Int) -> String.Index { currentIndex = message.characters.index(currentIndex, offsetBy: by) return currentIndex } - mutating func read(_ length: Int) -> String { - let readString = message[currentIndex.. String { + let readString = message[currentIndex.. String { + mutating func readUntilOccurence(of string: String) -> String { let substring = message[currentIndex.. String { - return read(message.characters.distance(from: currentIndex, to: message.endIndex)) + return read(count: message.characters.distance(from: currentIndex, to: message.endIndex)) } }