From b6d4904caca0febf776e6bf644b5318562f2f538 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sun, 14 Apr 2019 22:57:25 -0500 Subject: [PATCH] Support Swift 5 --- .travis.yml | 4 ++++ Package@swift-5.swift | 20 ++++++++++++++++++++ Sources/BluetoothLinux/HostController.swift | 10 +++++++--- Sources/BluetoothLinux/L2CAP.swift | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 Package@swift-5.swift diff --git a/.travis.yml b/.travis.yml index 181891c..c9b8a69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,10 @@ matrix: # Test Xcode 10 / Swift 4.2 - os: osx osx_image: xcode10 + # Test Xcode 10.2 / Swift 5 + - os: osx + osx_image: xcode10.2 + addons: apt: packages: diff --git a/Package@swift-5.swift b/Package@swift-5.swift new file mode 100644 index 0000000..54c6a13 --- /dev/null +++ b/Package@swift-5.swift @@ -0,0 +1,20 @@ +// swift-tools-version:5.0 +import PackageDescription + +_ = Package(name: "BluetoothLinux", + products: [ + .library( + name: "BluetoothLinux", + targets: ["BluetoothLinux"] + ) + ], + dependencies: [ + .package(url: "https://github.com/PureSwift/Bluetooth.git", .branch("master")) + ], + targets: [ + .target(name: "BluetoothLinux", dependencies: ["Bluetooth", "CSwiftBluetoothLinux"]), + .target(name: "CSwiftBluetoothLinux"), + .target(name: "CSwiftBluetoothLinuxTest"), + .testTarget(name: "BluetoothLinuxTests", dependencies: ["BluetoothLinux", "CSwiftBluetoothLinuxTest"]) + ], + swiftLanguageVersions: [.v5]) diff --git a/Sources/BluetoothLinux/HostController.swift b/Sources/BluetoothLinux/HostController.swift index 0d28818..2aa05d8 100644 --- a/Sources/BluetoothLinux/HostController.swift +++ b/Sources/BluetoothLinux/HostController.swift @@ -79,12 +79,16 @@ public extension HostController { static var `default`: HostController? { + #if swift(>=5.0) + guard let deviceIdentifier = try? HCIGetRoute(nil) + else { return nil } + #else guard let result = try? HCIGetRoute(nil), - let deviceIdentifier = result, - let controller = try? HostController(identifier: deviceIdentifier) + let deviceIdentifier = result else { return nil } + #endif - return controller + return try? HostController(identifier: deviceIdentifier) } } diff --git a/Sources/BluetoothLinux/L2CAP.swift b/Sources/BluetoothLinux/L2CAP.swift index 9220382..3d4ea7b 100644 --- a/Sources/BluetoothLinux/L2CAP.swift +++ b/Sources/BluetoothLinux/L2CAP.swift @@ -285,7 +285,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol { let actualBytes = Array(buffer.prefix(actualByteCount)) - return Data(bytes: actualBytes) + return Data(actualBytes) } private func canRead() throws -> Bool {