diff --git a/BencodeKit.xcodeproj/project.pbxproj b/BencodeKit.xcodeproj/project.pbxproj index da0297e..42e3565 100644 --- a/BencodeKit.xcodeproj/project.pbxproj +++ b/BencodeKit.xcodeproj/project.pbxproj @@ -211,15 +211,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0910; TargetAttributes = { 9EB798191E3AE7EA005A7C9E = { CreatedOnToolsVersion = 8.2.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; 9EB798221E3AE7EA005A7C9E = { CreatedOnToolsVersion = 8.2.1; + LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; }; @@ -321,12 +322,18 @@ 9EB798131E3AE7B7005A7C9E /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -346,12 +353,18 @@ 9EB798141E3AE7B7005A7C9E /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -426,7 +439,8 @@ SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -485,7 +499,8 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -546,7 +561,8 @@ SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; }; name = Debug; @@ -596,7 +612,8 @@ SDKROOT = ""; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2,3,4"; VALIDATE_PRODUCT = YES; }; diff --git a/BencodeKit.xcodeproj/xcshareddata/xcschemes/BencodeKit.xcscheme b/BencodeKit.xcodeproj/xcshareddata/xcschemes/BencodeKit.xcscheme index e508efd..2ece150 100644 --- a/BencodeKit.xcodeproj/xcshareddata/xcschemes/BencodeKit.xcscheme +++ b/BencodeKit.xcodeproj/xcshareddata/xcschemes/BencodeKit.xcscheme @@ -1,6 +1,6 @@ @@ -56,6 +57,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Cartfile.resolved b/Cartfile.resolved index f0e454d..68913a6 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "krzyzanowskim/CryptoSwift" "0.6.9" +github "krzyzanowskim/CryptoSwift" "0.7.2" diff --git a/Sources/Bencode.swift b/Sources/Bencode.swift index b348a16..0c98abf 100644 --- a/Sources/Bencode.swift +++ b/Sources/Bencode.swift @@ -62,11 +62,11 @@ public indirect enum Bencode: Equatable { return "i\(String(integer))e" case .bytes(let bytes): let string = bytes.asciiString - return "\(string.characters.count):\(string)" + return "\(string.count):\(string)" case .list(let list): return "l\(list.map { $0.encodedString() }.joined())e" case .dictionary(let dictionary): - return "d\(dictionary.map { "\($0.characters.count):\($0)\($1.encodedString())" }.joined())e" + return "d\(dictionary.map { "\($0.count):\($0)\($1.encodedString())" }.joined())e" } } @@ -119,7 +119,7 @@ public extension Bencode { case .list(let list): return "l".asciiData + list.map { $0.encoded() }.joined() + "e".asciiData case .dictionary(let dictionary): - return "d".asciiData + dictionary.map { "\($0.characters.count):\($0)".asciiData + $1.encoded() }.joined() + "e".asciiData + return "d".asciiData + dictionary.map { "\($0.count):\($0)".asciiData + $1.encoded() }.joined() + "e".asciiData } } } diff --git a/Sources/Types/Dictionary.swift b/Sources/Types/Dictionary.swift index 5cb3bd9..5078115 100644 --- a/Sources/Types/Dictionary.swift +++ b/Sources/Types/Dictionary.swift @@ -25,13 +25,11 @@ public struct OrderedDictionary: Collection { public var values: Array { return keys.flatMap { dictionary[$0] } } - private var dictionary: Dictionary = [:] + private var dictionary: Dictionary = [:] public init(_ elements: [(Key, Value)] = []) { self.keys = elements.map { $0.0 } - self.dictionary = elements.reduce(into: [:]) { dictionary, pair in - dictionary[pair.0] = pair.1 - } + self.dictionary = Dictionary(uniqueKeysWithValues: elements) } public init(_ elements: (Key, Value)...) { @@ -84,7 +82,7 @@ internal func bdecodeDictionary(_ data: Data, _ index: Data.Index) throws -> (Be let stringKey = key.reduce("") { string, byte in string.appendingFormat("%c", byte) } - values.append(stringKey, valueMatch) + values.append((stringKey, valueMatch)) currentIndex = nextIndex guard currentIndex != data.endIndex else { throw BencodingError.unterminatedDictionary(index)