Skip to content

Commit ef44666

Browse files
Swift 6 language mode support (#22)
- Adds dedicated package manifest files for Swift 6 - Adds required Sendable support - Marks some OSLogStore related elements with pre concurrency and retroactive (for testing purposes) - `OSLogClient.pollingInterval` now requires `async` - Updated shared instance structure to better support concurrency
1 parent 714dd9f commit ef44666

15 files changed

+219
-88
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -19,6 +19,9 @@ let package = Package(
1919
name: "OSLogClient",
2020
resources: [
2121
.copy("Resources/PrivacyInfo.xcprivacy")
22+
],
23+
swiftSettings: [
24+
.swiftLanguageMode(.v6)
2225
]
2326
),
2427
.testTarget(

[email protected]

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.10
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "OSLogClient",
8+
platforms: [.macOS(.v12), .iOS(.v15), .watchOS(.v8), .tvOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, making them visible to other packages.
11+
.library(
12+
name: "OSLogClient",
13+
targets: ["OSLogClient"]),
14+
],
15+
targets: [
16+
// Targets are the basic building blocks of a package, defining a module or a test suite.
17+
// Targets can depend on other targets in this package and products from dependencies.
18+
.target(
19+
name: "OSLogClient",
20+
resources: [
21+
.copy("Resources/PrivacyInfo.xcprivacy")
22+
]
23+
),
24+
.testTarget(
25+
name: "OSLogClientTests",
26+
dependencies: ["OSLogClient"]
27+
),
28+
]
29+
)

[email protected]

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "OSLogClient",
8+
platforms: [.macOS(.v12), .iOS(.v15), .watchOS(.v8), .tvOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, making them visible to other packages.
11+
.library(
12+
name: "OSLogClient",
13+
targets: ["OSLogClient"]),
14+
],
15+
targets: [
16+
// Targets are the basic building blocks of a package, defining a module or a test suite.
17+
// Targets can depend on other targets in this package and products from dependencies.
18+
.target(
19+
name: "OSLogClient",
20+
resources: [
21+
.copy("Resources/PrivacyInfo.xcprivacy")
22+
]
23+
),
24+
.testTarget(
25+
name: "OSLogClientTests",
26+
dependencies: ["OSLogClient"]
27+
),
28+
]
29+
)

Sources/OSLogClient/Internal/ProcessInfoProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
/// Internal protocol used to facilitate unit-testing only support for some scenarios.
1111
/// This is due to not being able to use a traditional spy/mock setup for actors.
12-
protocol ProcessInfoEnvironmentProvider: AnyObject {
12+
protocol ProcessInfoEnvironmentProvider: AnyObject, Sendable {
1313

1414
/// Dictionary of environment variables available from the current process.
1515
var processInfoEnvironment: [String : String] { get }

Sources/OSLogClient/Public/LastProcessedStrategy/InMemoryLastProcessedStrategy.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
// Created by Joshua Asbury on 24/8/2024.
66
//
77

8-
public class InMemoryLastProcessedStrategy: LastProcessedStrategy {
8+
public final class InMemoryLastProcessedStrategy: LastProcessedStrategy, Equatable, @unchecked Sendable {
9+
910
public var date: Date?
1011

1112
public func setLastProcessedDate(_ date: Date?) {
1213
self.date = date
1314
}
15+
16+
public static func == (lhs: InMemoryLastProcessedStrategy, rhs: InMemoryLastProcessedStrategy) -> Bool {
17+
lhs.date == rhs.date
18+
}
1419
}
1520

1621
public extension LastProcessedStrategy where Self == InMemoryLastProcessedStrategy {

Sources/OSLogClient/Public/LastProcessedStrategy/LastProcessedStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// Enumeration of supported strategies for storing and updating the `Date` the log store was last successfully queried and processed.
11-
public protocol LastProcessedStrategy {
11+
public protocol LastProcessedStrategy: Sendable {
1212
/// The most recent `Date` of a processed/polled log
1313
var date: Date? { get }
1414

Sources/OSLogClient/Public/LastProcessedStrategy/UserDefaultsLastProcessedStrategy.swift

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,37 @@
77

88
import Foundation
99

10-
public struct UserDefaultsLastProcessedStrategy: LastProcessedStrategy {
11-
let defaults: UserDefaults
10+
final class SendableUserDefaults: @unchecked Sendable {
11+
12+
var target: UserDefaults
13+
14+
init(_ target: UserDefaults) {
15+
self.target = target
16+
}
17+
18+
func setValue(_ value: Any?, forKey key: String) {
19+
target.set(value, forKey: key)
20+
}
21+
22+
func value(forKey key: String) -> Any? {
23+
target.value(forKey: key)
24+
}
25+
26+
func removeObject(forKey defaultName: String) {
27+
target.removeObject(forKey: defaultName)
28+
}
29+
}
30+
31+
public struct UserDefaultsLastProcessedStrategy: LastProcessedStrategy, Equatable, Sendable {
32+
33+
// MARK: - Properties
34+
35+
var sendableDefaults: SendableUserDefaults
36+
37+
var defaults: UserDefaults {
38+
sendableDefaults.target
39+
}
40+
1241
let key: String
1342

1443
public var date: Date? {
@@ -18,9 +47,11 @@ public struct UserDefaultsLastProcessedStrategy: LastProcessedStrategy {
1847
return Date(timeIntervalSince1970: timestamp)
1948
}
2049

50+
// MARK: - Lifecycle
51+
2152
public init(key: String, defaults: UserDefaults = .standard) {
2253
self.key = key
23-
self.defaults = defaults
54+
self.sendableDefaults = SendableUserDefaults(defaults)
2455
}
2556

2657
public mutating func setLastProcessedDate(_ date: Date?) {
@@ -30,6 +61,10 @@ public struct UserDefaultsLastProcessedStrategy: LastProcessedStrategy {
3061
defaults.removeObject(forKey: key)
3162
}
3263
}
64+
65+
public static func == (lhs: UserDefaultsLastProcessedStrategy, rhs: UserDefaultsLastProcessedStrategy) -> Bool {
66+
lhs.date == rhs.date
67+
}
3368
}
3469

3570
public extension LastProcessedStrategy where Self == UserDefaultsLastProcessedStrategy {

Sources/OSLogClient/Public/LogDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import OSLog
1111
/// `LogDriver` instances are responsible for handling processed os logs.
1212
/// Instances, when registered with the ``OSLogClient`` instance, will be sent logs from the `OSLogStore`.
1313
/// If ``LogFilter``s are provided any incoming logs will be assessed against the filter rules and ignored if no matches are found.
14-
open class LogDriver: Equatable {
14+
open class LogDriver: Equatable, @unchecked Sendable {
1515
// MARK: - Supplementary
1616

1717
/// Enumeration of supported log levels.

0 commit comments

Comments
 (0)