Skip to content

Commit d828868

Browse files
authored
Merge pull request #29 from PureSwift/feature/async
Added Swift Concurrency support
2 parents c3b7447 + daa2113 commit d828868

38 files changed

+3372
-2688
lines changed

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: macOS-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v1
14+
uses: actions/checkout@v2
1515
- name: Xcode Version
1616
run: |
1717
xcodebuild -version

.github/workflows/swift.yml

+1-22
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,13 @@ on: [push]
44

55
jobs:
66

7-
macOS-swift:
8-
name: macOS
9-
runs-on: macOS-latest
10-
steps:
11-
- name: Checkout
12-
uses: actions/checkout@v1
13-
- name: Xcode Version
14-
run: |
15-
xcodebuild -version
16-
swift --version
17-
- name: Swift Version
18-
run: swift --version
19-
- name: Build (Debug)
20-
run: swift build -c debug
21-
- name: Build (Release)
22-
run: swift build -c release
23-
- name: Test (Debug)
24-
run: swift test --configuration debug --enable-test-discovery
25-
- name: Test (Release)
26-
run: swift test --configuration release -Xswiftc -enable-testing --enable-test-discovery
27-
287
linux-swift:
298
name: Linux x86_64
309
runs-on: ubuntu-20.04
3110
container: swift:5.6.1-focal
3211
steps:
3312
- name: Checkout
34-
uses: actions/checkout@v1
13+
uses: actions/checkout@v2
3514
- name: Swift Version
3615
run: swift --version
3716
- name: Build (Debug)

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Package.pins
4040
.build/
4141
GATT.xcodeproj/*
4242
*.resolved
43+
.swiftpm
4344

4445
# CocoaPods
4546
#

Package.swift

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let libraryType: PackageDescription.Product.Library.LibraryType = .static
55

66
let package = Package(
77
name: "GATT",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.watchOS(.v6),
12+
.tvOS(.v13),
13+
],
814
products: [
915
.library(
1016
name: "GATT",
@@ -13,7 +19,6 @@ let package = Package(
1319
),
1420
.library(
1521
name: "DarwinGATT",
16-
type: libraryType,
1722
targets: ["DarwinGATT"]
1823
)
1924
],
@@ -27,20 +32,58 @@ let package = Package(
2732
.target(
2833
name: "GATT",
2934
dependencies: [
30-
"Bluetooth"
35+
.product(
36+
name: "Bluetooth",
37+
package: "Bluetooth"
38+
),
39+
.product(
40+
name: "BluetoothGATT",
41+
package: "Bluetooth",
42+
condition: .when(platforms: [.macOS, .linux])
43+
),
44+
.product(
45+
name: "BluetoothGAP",
46+
package: "Bluetooth",
47+
condition: .when(platforms: [.macOS, .linux])
48+
),
49+
.product(
50+
name: "BluetoothHCI",
51+
package: "Bluetooth",
52+
condition: .when(platforms: [.macOS, .linux])
53+
),
3154
]
3255
),
3356
.target(
3457
name: "DarwinGATT",
3558
dependencies: [
36-
"GATT"
59+
"GATT",
60+
.product(
61+
name: "BluetoothGATT",
62+
package: "Bluetooth",
63+
condition: .when(platforms: [.macOS])
64+
)
3765
]
3866
),
3967
.testTarget(
4068
name: "GATTTests",
4169
dependencies: [
4270
"GATT",
43-
"Bluetooth"
71+
.product(
72+
name: "Bluetooth",
73+
package: "Bluetooth"
74+
),
75+
.product(
76+
name: "BluetoothGATT",
77+
package: "Bluetooth"
78+
),
79+
.product(
80+
name: "BluetoothGAP",
81+
package: "Bluetooth"
82+
),
83+
.product(
84+
name: "BluetoothHCI",
85+
package: "Bluetooth"
86+
)
4487
]
4588
)
4689
]

[email protected]

-85
This file was deleted.

Sources/DarwinGATT/DarwinAttributes.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension GATTAttribute.Characteristic: CoreBluetoothAttributeConvertible {
5555

5656
extension GATTAttribute.Descriptor: CoreBluetoothAttributeConvertible {
5757

58-
func toCoreBluetooth() -> CBDescriptor {
58+
func toCoreBluetooth() -> CBMutableDescriptor {
5959

6060
/*
6161
Only the Characteristic User Description and Characteristic Presentation Format descriptors are currently supported. The Characteristic Extended Properties and Client Characteristic Configuration descriptors will be created automatically upon publication of the parent service, depending on the properties of the characteristic itself
@@ -66,10 +66,10 @@ extension GATTAttribute.Descriptor: CoreBluetoothAttributeConvertible {
6666
```
6767
*/
6868

69-
guard let descriptor = DarwinDescriptor(uuid: uuid, data: value)
69+
guard let descriptor = CBMutableDescriptor(uuid: self.uuid, data: self.value)
7070
else { fatalError("Unsupported \(CBDescriptor.self) \(uuid)") }
7171

72-
return CBMutableDescriptor(descriptor)
72+
return descriptor
7373
}
7474
}
7575

Sources/DarwinGATT/DarwinBluetoothState.swift

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88

99
#if canImport(CoreBluetooth)
10-
1110
import Foundation
11+
import CoreBluetooth
1212

1313
/// Darwin Bluetooth State
1414
///
@@ -46,4 +46,17 @@ extension DarwinBluetoothState: CustomStringConvertible {
4646
}
4747
}
4848

49+
internal extension CBCentralManager {
50+
51+
var _state: DarwinBluetoothState {
52+
return unsafeBitCast(self.state, to: DarwinBluetoothState.self)
53+
}
54+
}
55+
56+
internal extension CBPeripheralManager {
57+
58+
var _state: DarwinBluetoothState {
59+
return unsafeBitCast(self.state, to: DarwinBluetoothState.self)
60+
}
61+
}
4962
#endif

0 commit comments

Comments
 (0)