Skip to content

Commit

Permalink
Update to Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Qata committed Oct 7, 2017
1 parent a508793 commit bce38af
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
29 changes: 23 additions & 6 deletions BencodeKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand Down Expand Up @@ -56,6 +57,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "krzyzanowskim/CryptoSwift" "0.6.9"
github "krzyzanowskim/CryptoSwift" "0.7.2"
6 changes: 3 additions & 3 deletions Sources/Bencode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions Sources/Types/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public struct OrderedDictionary<Key: Hashable, Value>: Collection {
public var values: Array<Value> {
return keys.flatMap { dictionary[$0] }
}
private var dictionary: Dictionary<Key,Value> = [:]
private var dictionary: Dictionary<Key, Value> = [:]

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)...) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bce38af

Please sign in to comment.