Skip to content

Commit fe2fd54

Browse files
committed
update
1 parent 74a084b commit fe2fd54

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

Sources/bluetooth-law-energy-swift/ext/CBPeripheral+.swift

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,31 @@
66
//
77

88
import CoreBluetooth
9-
9+
import Foundation
1010

1111
/// Extension of CBPeripheral to include computed properties related to the connection state and identity of Bluetooth peripherals.
12-
@available(macOS 12, iOS 15, tvOS 15.0, watchOS 8.0, *)
13-
public extension CBPeripheral {
12+
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *)
13+
extension CBPeripheral {
1414

1515
// MARK: - Computed Properties
1616

1717
/// Checks if the peripheral is connected.
18-
var isConnected: Bool {
18+
public var isConnected: Bool {
1919
self.state == .connected
2020
}
2121

2222
/// Checks if the peripheral is not connected.
23-
var isNotConnected: Bool {
23+
public var isNotConnected: Bool {
2424
self.state != .connected
2525
}
2626

2727
/// Retrieves the identifier of the peripheral.
28-
var getId: UUID {
28+
public var getId: UUID {
2929
return self.identifier
3030
}
3131

3232
/// Retrieves the name of the peripheral. If the name is nil, returns "unknown".
33-
var getName: String {
33+
public var getName: String {
3434
name ?? "unknown"
3535
}
3636
}
37-
38-
39-
fileprivate func censorWords(in text: String, using words: [String]) -> String {
40-
var censoredText = text
41-
42-
for word in words {
43-
let pattern = "\\b\(word)\\b"
44-
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
45-
let range = NSRange(location: 0, length: censoredText.utf16.count)
46-
censoredText = regex.stringByReplacingMatches(in: censoredText, options: [], range: range, withTemplate: String(repeating: "*", count: word.count))
47-
}
48-
49-
return censoredText
50-
}

Sources/bluetooth-law-energy-swift/ext/Task+.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ import Foundation
99

1010

1111
/// Extends Task to provide a sleep function when used in an async context.
12-
@available(iOS, introduced: 15.0)
13-
@available(macOS, introduced: 12.0)
14-
@available(watchOS, introduced: 8.0)
15-
@available(tvOS, introduced: 15.0)
12+
@available(iOS 15, *)
13+
@available(macOS 12, *)
14+
@available(watchOS 8, *)
15+
@available(tvOS 15, *)
1616
extension Task where Success == Never, Failure == Never {
17-
18-
/// Suspends the current task for the given time interval.
19-
///
20-
/// - Parameter duration: The time interval to sleep for.
21-
static func sleep(for duration: Double) async throws {
22-
if #available(iOS 16, macOS 13, tvOS 16.0, watchOS 9.0, *) {
23-
try await Task.sleep(for: .seconds(duration))
24-
} else {
25-
try await Task.sleep(nanoseconds: UInt64(duration * 1_000_000_000))
26-
}
17+
18+
@available(iOS, deprecated: 16.0, message: "Use Task.sleep(for: .seconds(_)) on iOS 16+")
19+
@available(macOS, deprecated: 13.0, message: "Use Task.sleep(for: .seconds(_)) on macOS 13+")
20+
@available(watchOS, deprecated: 9.0, message: "Use Task.sleep(for: .seconds(_)) on watchOS 9+")
21+
@available(tvOS, deprecated: 16.0, message: "Use Task.sleep(for: .seconds(_)) on tvOS 16+")
22+
static func sleep(for seconds: Double) async throws {
23+
// Не зовём новый API, чтобы не пересекаться по имени.
24+
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
2725
}
2826
}

Sources/bluetooth-law-energy-swift/service/StreamRegistration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ extension BluetoothLEManager {
9494
let id = register(newContinuation)
9595

9696
newContinuation.onTermination = { [weak self] _ in
97+
guard let self = self else { return }
9798
Task {
98-
guard let self = self else { return }
9999
await self.unregister(with: id)
100100
}
101101
}

0 commit comments

Comments
 (0)