Skip to content

Commit bce38af

Browse files
committed
Update to Swift 4
1 parent a508793 commit bce38af

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

BencodeKit.xcodeproj/project.pbxproj

+23-6
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,16 @@
211211
isa = PBXProject;
212212
attributes = {
213213
LastSwiftUpdateCheck = 0820;
214-
LastUpgradeCheck = 0820;
214+
LastUpgradeCheck = 0910;
215215
TargetAttributes = {
216216
9EB798191E3AE7EA005A7C9E = {
217217
CreatedOnToolsVersion = 8.2.1;
218-
LastSwiftMigration = 0820;
218+
LastSwiftMigration = 0910;
219219
ProvisioningStyle = Automatic;
220220
};
221221
9EB798221E3AE7EA005A7C9E = {
222222
CreatedOnToolsVersion = 8.2.1;
223+
LastSwiftMigration = 0910;
223224
ProvisioningStyle = Automatic;
224225
};
225226
};
@@ -321,12 +322,18 @@
321322
9EB798131E3AE7B7005A7C9E /* Debug */ = {
322323
isa = XCBuildConfiguration;
323324
buildSettings = {
325+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
324326
CLANG_WARN_BOOL_CONVERSION = YES;
327+
CLANG_WARN_COMMA = YES;
325328
CLANG_WARN_CONSTANT_CONVERSION = YES;
326329
CLANG_WARN_EMPTY_BODY = YES;
327330
CLANG_WARN_ENUM_CONVERSION = YES;
328331
CLANG_WARN_INFINITE_RECURSION = YES;
329332
CLANG_WARN_INT_CONVERSION = YES;
333+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
334+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
335+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
336+
CLANG_WARN_STRICT_PROTOTYPES = YES;
330337
CLANG_WARN_SUSPICIOUS_MOVE = YES;
331338
CLANG_WARN_UNREACHABLE_CODE = YES;
332339
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -346,12 +353,18 @@
346353
9EB798141E3AE7B7005A7C9E /* Release */ = {
347354
isa = XCBuildConfiguration;
348355
buildSettings = {
356+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
349357
CLANG_WARN_BOOL_CONVERSION = YES;
358+
CLANG_WARN_COMMA = YES;
350359
CLANG_WARN_CONSTANT_CONVERSION = YES;
351360
CLANG_WARN_EMPTY_BODY = YES;
352361
CLANG_WARN_ENUM_CONVERSION = YES;
353362
CLANG_WARN_INFINITE_RECURSION = YES;
354363
CLANG_WARN_INT_CONVERSION = YES;
364+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
365+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
366+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
367+
CLANG_WARN_STRICT_PROTOTYPES = YES;
355368
CLANG_WARN_SUSPICIOUS_MOVE = YES;
356369
CLANG_WARN_UNREACHABLE_CODE = YES;
357370
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -426,7 +439,8 @@
426439
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
427440
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
428441
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
429-
SWIFT_VERSION = 3.0;
442+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
443+
SWIFT_VERSION = 4.0;
430444
TARGETED_DEVICE_FAMILY = "1,2,3,4";
431445
VERSIONING_SYSTEM = "apple-generic";
432446
VERSION_INFO_PREFIX = "";
@@ -485,7 +499,8 @@
485499
SKIP_INSTALL = YES;
486500
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
487501
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
488-
SWIFT_VERSION = 3.0;
502+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
503+
SWIFT_VERSION = 4.0;
489504
TARGETED_DEVICE_FAMILY = "1,2,3,4";
490505
VALIDATE_PRODUCT = YES;
491506
VERSIONING_SYSTEM = "apple-generic";
@@ -546,7 +561,8 @@
546561
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
547562
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
548563
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
549-
SWIFT_VERSION = 3.0;
564+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
565+
SWIFT_VERSION = 4.0;
550566
TARGETED_DEVICE_FAMILY = "1,2,3,4";
551567
};
552568
name = Debug;
@@ -596,7 +612,8 @@
596612
SDKROOT = "";
597613
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator";
598614
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
599-
SWIFT_VERSION = 3.0;
615+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
616+
SWIFT_VERSION = 4.0;
600617
TARGETED_DEVICE_FAMILY = "1,2,3,4";
601618
VALIDATE_PRODUCT = YES;
602619
};

BencodeKit.xcodeproj/xcshareddata/xcschemes/BencodeKit.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0820"
3+
LastUpgradeVersion = "0910"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES"
3031
codeCoverageEnabled = "YES">
3132
<Testables>
@@ -56,6 +57,7 @@
5657
buildConfiguration = "Debug"
5758
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5859
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
60+
language = ""
5961
launchStyle = "0"
6062
useCustomWorkingDirectory = "NO"
6163
ignoresPersistentStateOnLaunch = "NO"

Cartfile.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "krzyzanowskim/CryptoSwift" "0.6.9"
1+
github "krzyzanowskim/CryptoSwift" "0.7.2"

Sources/Bencode.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ public indirect enum Bencode: Equatable {
6262
return "i\(String(integer))e"
6363
case .bytes(let bytes):
6464
let string = bytes.asciiString
65-
return "\(string.characters.count):\(string)"
65+
return "\(string.count):\(string)"
6666
case .list(let list):
6767
return "l\(list.map { $0.encodedString() }.joined())e"
6868
case .dictionary(let dictionary):
69-
return "d\(dictionary.map { "\($0.characters.count):\($0)\($1.encodedString())" }.joined())e"
69+
return "d\(dictionary.map { "\($0.count):\($0)\($1.encodedString())" }.joined())e"
7070
}
7171
}
7272

@@ -119,7 +119,7 @@ public extension Bencode {
119119
case .list(let list):
120120
return "l".asciiData + list.map { $0.encoded() }.joined() + "e".asciiData
121121
case .dictionary(let dictionary):
122-
return "d".asciiData + dictionary.map { "\($0.characters.count):\($0)".asciiData + $1.encoded() }.joined() + "e".asciiData
122+
return "d".asciiData + dictionary.map { "\($0.count):\($0)".asciiData + $1.encoded() }.joined() + "e".asciiData
123123
}
124124
}
125125
}

Sources/Types/Dictionary.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ public struct OrderedDictionary<Key: Hashable, Value>: Collection {
2525
public var values: Array<Value> {
2626
return keys.flatMap { dictionary[$0] }
2727
}
28-
private var dictionary: Dictionary<Key,Value> = [:]
28+
private var dictionary: Dictionary<Key, Value> = [:]
2929

3030
public init(_ elements: [(Key, Value)] = []) {
3131
self.keys = elements.map { $0.0 }
32-
self.dictionary = elements.reduce(into: [:]) { dictionary, pair in
33-
dictionary[pair.0] = pair.1
34-
}
32+
self.dictionary = Dictionary(uniqueKeysWithValues: elements)
3533
}
3634

3735
public init(_ elements: (Key, Value)...) {
@@ -84,7 +82,7 @@ internal func bdecodeDictionary(_ data: Data, _ index: Data.Index) throws -> (Be
8482
let stringKey = key.reduce("") { string, byte in
8583
string.appendingFormat("%c", byte)
8684
}
87-
values.append(stringKey, valueMatch)
85+
values.append((stringKey, valueMatch))
8886
currentIndex = nextIndex
8987
guard currentIndex != data.endIndex else {
9088
throw BencodingError.unterminatedDictionary(index)

0 commit comments

Comments
 (0)