Skip to content

Commit cf4fa00

Browse files
committed
Deprecated Swift 4
1 parent 6d916b1 commit cf4fa00

File tree

17 files changed

+14
-1689
lines changed

17 files changed

+14
-1689
lines changed

.travis.yml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
language: generic
22
matrix:
33
include:
4-
# Test Ubuntu Linux 14.04 / Swift 4.1.2
4+
# Test Ubuntu Linux 16.04 / Swift 5
55
- os: linux
6-
dist: trusty
6+
dist: xenial
77
sudo: required
8-
# Test Xcode 9.3 / Swift 4.1.0
9-
- os: osx
10-
osx_image: xcode9.3
11-
# Test Xcode 9.4.1 / Swift 4.1.2
12-
- os: osx
13-
osx_image: xcode9.4
14-
# Test Xcode 10 / Swift 4.2
15-
- os: osx
16-
osx_image: xcode10
8+
env:
9+
- SWIFT_VERSION=swift-5.0-RELEASE
10+
- SWIFT_URL=https://swift.org/builds/swift-5.0-release/ubuntu1604/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu16.04.tar.gz
11+
install:
12+
- export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu16.04/usr/bin:"${PATH}"
1713
# Test Xcode 10.2 / Swift 5
1814
- os: osx
1915
osx_image: xcode10.2
20-
2116
addons:
2217
apt:
2318
packages:
2419
- clang
2520
- pkg-config
26-
install:
27-
# Install Swift 4.1.2 on Ubuntu Linux 14.04
28-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then SWIFT_DIR=tests ; fi
29-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi
30-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl https://swift.org/builds/swift-4.1.2-release/ubuntu1404/swift-4.1.2-RELEASE/swift-4.1.2-RELEASE-ubuntu14.04.tar.gz -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi
21+
script:
22+
# Setup Linux environment
3123
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update ; fi
3224
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install clang ; fi
33-
env:
34-
- SWIFT_VERSION=swift-4.1.2-RELEASE
35-
script:
36-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$(pwd)/tests/$SWIFT_VERSION-ubuntu14.04/usr/bin:"${PATH}" ; fi
37-
# Compile with SPM
25+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then SWIFT_DIR=tests ; fi
26+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir $SWIFT_DIR ; fi
27+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl $SWIFT_URL -s | tar xz -C $SWIFT_DIR &> /dev/null ; fi
28+
# Run Unit Tests
3829
- swift test
39-
# Compile with Xcode
40-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cd Xcode ; fi
41-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xcodebuild clean test -scheme TLVCoding-macOS ; fi
42-
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xcodebuild clean build -scheme TLVCoding-iOS ; fi

[email protected]

Lines changed: 0 additions & 15 deletions
This file was deleted.

[email protected]

Lines changed: 0 additions & 15 deletions
This file was deleted.

Sources/CodingKey.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public extension TLVCodingKey where Self: RawRepresentable, Self.RawValue == TLV
4040
}
4141
}
4242

43-
#if swift(>=4.2)
4443
public extension TLVCodingKey where Self: CaseIterable, Self: RawRepresentable, Self.RawValue == TLVTypeCode.RawValue {
4544

4645
init?(stringValue: String) {
@@ -51,7 +50,6 @@ public extension TLVCodingKey where Self: CaseIterable, Self: RawRepresentable,
5150
self = value
5251
}
5352
}
54-
#endif
5553

5654
internal extension TLVTypeCode {
5755

@@ -98,21 +96,11 @@ internal extension CodingKey {
9896
static var sanitizedName: String {
9997

10098
let rawName = String(reflecting: self)
101-
#if swift(>=5.0)
10299
var elements = rawName.split(separator: ".")
103-
#else
104-
var elements = rawName.components(separatedBy: ".")
105-
#endif
106100
guard elements.count > 2
107101
else { return rawName }
108102
elements.removeFirst()
109-
#if swift(>=5.0)
110103
elements.removeAll { $0.contains("(unknown context") }
111-
#else
112-
while let index = elements.index(where: { $0.contains("(unknown context") }) {
113-
elements.remove(at: index)
114-
}
115-
#endif
116104
return elements.reduce("", { $0 + ($0.isEmpty ? "" : ".") + $1 })
117105
}
118106
}

Sources/Data.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,38 @@ import Foundation
1010

1111
internal extension Data {
1212

13-
#if swift(>=5.0) || (swift(>=4.2) && XCODE)
1413
func subdataNoCopy(in range: Range<Int>) -> Data {
1514

1615
// stored in heap, can reuse buffer
1716
if count > Data.inlineBufferSize {
1817

19-
#if swift(>=5.0)
2018
return withUnsafeBytes { (buffer: UnsafeRawBufferPointer) in
2119
Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: buffer.baseAddress!.advanced(by: range.lowerBound)),
2220
count: range.count,
2321
deallocator: .none)
2422
}
25-
#else
26-
return withUnsafeBytes {
27-
Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0.advanced(by: range.lowerBound)),
28-
count: range.count,
29-
deallocator: .none)
30-
}
31-
#endif
3223

3324
} else {
3425

3526
// stored in stack, must copy
3627
return subdata(in: range)
3728
}
3829
}
39-
#elseif swift(>=4.2)
40-
func subdataNoCopy(in range: Range<Int>) -> Data {
41-
42-
return withUnsafeBytes {
43-
Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: $0.advanced(by: range.lowerBound)),
44-
count: range.count,
45-
deallocator: .none)
46-
}
47-
}
48-
#elseif swift(>=4.0)
49-
func subdataNoCopy(in range: CountableRange<Int>) -> Data {
50-
51-
let pointer = withUnsafeBytes { UnsafeMutableRawPointer(mutating: $0).advanced(by: range.lowerBound) }
52-
return Data(bytesNoCopy: pointer, count: range.count, deallocator: .none)
53-
}
54-
55-
/// Returns a new copy of the data in a specified range.
56-
func subdata(in range: CountableRange<Int>) -> Data {
57-
return Data(self[range])
58-
}
59-
#endif
6030

6131
func suffixNoCopy(from index: Int) -> Data {
62-
6332
return subdataNoCopy(in: index ..< count)
6433
}
6534

6635
func suffixCheckingBounds(from start: Int) -> Data {
6736

6837
if count > start {
69-
7038
return Data(suffix(from: start))
71-
7239
} else {
73-
7440
return Data()
7541
}
7642
}
7743
}
7844

79-
#if swift(>=5.0) || (swift(>=4.2) && XCODE)
8045
private extension Data {
8146

8247
/// Size of the inline buffer for `Foundation.Data` used in Swift 5.
@@ -97,4 +62,3 @@ private extension Data {
9762
return MemoryLayout<Buffer>.size
9863
}
9964
}
100-
#endif

Sources/DataConvertible.swift

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,12 @@ extension UnsafeDataConvertible {
4848

4949
/// Append data representation into buffer.
5050
static func += <T: DataContainer> (data: inout T, value: Self) {
51-
#if swift(>=4.2)
52-
withUnsafePointer(to: value) {
53-
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<Self>.size) {
54-
data.append($0, count: MemoryLayout<Self>.size)
55-
}
56-
}
57-
#else
5851
var value = value
5952
withUnsafePointer(to: &value) {
6053
$0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout<Self>.size) {
6154
data.append($0, count: MemoryLayout<Self>.size)
6255
}
6356
}
64-
#endif
6557
}
6658
}
6759

@@ -85,35 +77,21 @@ internal protocol DataContainer: RandomAccessCollection where Self.Index == Int
8577

8678
mutating func append <C: Collection> (contentsOf bytes: C) where C.Element == UInt8
8779

88-
#if swift(>=4.2)
8980
static func += (lhs: inout Self, rhs: UInt8)
81+
9082
static func += <C: Collection> (lhs: inout Self, rhs: C) where C.Element == UInt8
91-
#endif
9283
}
9384

9485
extension DataContainer {
9586

96-
#if swift(>=4.2)
97-
#else
98-
static func += (lhs: inout Self, rhs: UInt8) {
99-
lhs.append(rhs)
100-
}
101-
102-
static func += <C: Collection> (lhs: inout Self, rhs: C) where C.Element == UInt8 {
103-
lhs.append(contentsOf: rhs)
104-
}
105-
#endif
106-
10787
mutating func append <T: DataConvertible> (_ value: T) {
10888
self += value
10989
}
11090
}
11191

11292
extension Data: DataContainer {
11393

114-
#if swift(>=4.2)
11594
static func += (lhs: inout Data, rhs: UInt8) {
11695
lhs.append(rhs)
11796
}
118-
#endif
11997
}

Sources/Encoder.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,7 @@ private extension TLVEncodable {
594594

595595
var copyingBytes: Data {
596596

597-
#if swift(>=5)
598597
return withUnsafePointer(to: self, { Data(bytes: $0, count: MemoryLayout<Self>.size) })
599-
#else
600-
var copy = self
601-
return withUnsafePointer(to: &copy, { Data(bytes: $0, count: MemoryLayout<Self>.size) })
602-
#endif
603598
}
604599
}
605600

Tests/TLVCodingTests/TLVCodingTests.swift

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,6 @@ extension ProvisioningState.CodingKeys {
296296
}
297297
}
298298

299-
#if swift(>=4.2)
300-
#else
301-
extension ProvisioningState.CodingKeys {
302-
303-
static let allCases: Set<ProvisioningState.CodingKeys> = [.state, .result]
304-
305-
init?(stringValue: String) {
306-
307-
guard let value = type(of: self).allCases.first(where: { $0.stringValue == stringValue })
308-
else { return nil }
309-
310-
self = value
311-
}
312-
}
313-
#endif
314-
315299
public struct Profile: Codable, Equatable {
316300

317301
public var person: Person
@@ -420,11 +404,6 @@ public extension DeviceInformation {
420404
case bluetooth = 0b001
421405
case camera = 0b010
422406
case gps = 0b100
423-
424-
#if swift(>=4.2)
425-
#else
426-
public static let allCases: Set<DeviceInformation.Feature> = [.bluetooth, .camera, .gps]
427-
#endif
428407
}
429408
}
430409

@@ -607,25 +586,6 @@ extension CustomEncodableArray: Codable {
607586
}
608587
}
609588

610-
611-
#if swift(>=4.2)
612-
#else
613-
/// A type that provides a collection of all of its values.
614-
///
615-
/// Types that conform to the `CaseIterable` protocol are typically
616-
/// enumerations without associated values. When using a `CaseIterable` type,
617-
/// you can access a collection of all of the type's cases by using the type's
618-
/// `allCases` property.
619-
public protocol CaseIterable {
620-
621-
/// A type that can represent a collection of all values of this type.
622-
associatedtype AllCases: Collection where Self.AllCases.Element == Self
623-
624-
/// A collection of all values of this type.
625-
static var allCases: Self.AllCases { get }
626-
}
627-
#endif
628-
629589
/// Enum that represents a bit mask flag / option.
630590
///
631591
/// Basically `Swift.OptionSet` for enums.
@@ -763,15 +723,9 @@ extension BitMaskOptionSet: CustomStringConvertible {
763723

764724
extension BitMaskOptionSet: Hashable {
765725

766-
#if swift(>=4.2)
767726
public func hash(into hasher: inout Hasher) {
768727
rawValue.hash(into: &hasher)
769728
}
770-
#else
771-
public var hashValue: Int {
772-
return rawValue.hashValue
773-
}
774-
#endif
775729
}
776730

777731
extension BitMaskOptionSet: ExpressibleByArrayLiteral {

Xcode/Configs/TLVCoding.plist

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)