Skip to content

Commit fe3ede7

Browse files
authored
Guard changes with canImport for older Xcode versions
1 parent 309c7f2 commit fe3ede7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

SimpleKeychain/Accessibility.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Security
22

33
/// Represents the accessibility types of Keychain items. It's a mirror of `kSecAttrAccessible` values.
4-
public enum Accessibility: RawRepresentable, Sendable {
4+
public enum Accessibility: RawRepresentable {
55

66
/// The data in the Keychain item can be accessed only while the device is unlocked by the user.
77
/// See [kSecAttrAccessibleWhenUnlocked](https://developer.apple.com/documentation/security/ksecattraccessiblewhenunlocked).
@@ -50,3 +50,9 @@ public enum Accessibility: RawRepresentable, Sendable {
5050
}
5151
}
5252
}
53+
54+
// MARK: - Sendable conformance
55+
56+
#if canImport(_Concurrency)
57+
extension Accessibility: Sendable {}
58+
#endif

SimpleKeychain/SimpleKeychain.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import Foundation
22
import Security
33
#if canImport(LocalAuthentication)
4+
#if canImport(_Concurrency)
45
@preconcurrency import LocalAuthentication
6+
#else
7+
// swiftlint:disable:next duplicate_imports
8+
import LocalAuthentication
9+
#endif
510
#endif
611

712
typealias RetrieveFunction = (_ query: CFDictionary, _ result: UnsafeMutablePointer<CFTypeRef?>?) -> OSStatus
@@ -10,16 +15,22 @@ typealias RemoveFunction = (_ query: CFDictionary) -> OSStatus
1015
/// A simple Keychain wrapper for iOS, macOS, tvOS, and watchOS.
1116
/// Supports sharing credentials with an **access group** or through **iCloud**, and integrating
1217
/// **Touch ID / Face ID**.
13-
public struct SimpleKeychain: Sendable {
18+
public struct SimpleKeychain {
1419
let service: String
1520
let accessGroup: String?
1621
let accessibility: Accessibility
1722
let accessControlFlags: SecAccessControlCreateFlags?
1823
let isSynchronizable: Bool
19-
nonisolated(unsafe) let attributes: [String: Any]
2024

25+
#if canImport(_Concurrency)
26+
nonisolated(unsafe) let attributes: [String: Any]
2127
nonisolated(unsafe) var retrieve: RetrieveFunction = SecItemCopyMatching
2228
nonisolated(unsafe) var remove: RemoveFunction = SecItemDelete
29+
#else
30+
let attributes: [String: Any]
31+
var retrieve: RetrieveFunction = SecItemCopyMatching
32+
var remove: RemoveFunction = SecItemDelete
33+
#endif
2334

2435
#if canImport(LocalAuthentication) && !os(tvOS)
2536
let context: LAContext?
@@ -321,3 +332,9 @@ extension SimpleKeychain {
321332
return query
322333
}
323334
}
335+
336+
// MARK: - Sendable conformance
337+
338+
#if canImport(_Concurrency)
339+
extension SimpleKeychain: Sendable {}
340+
#endif

0 commit comments

Comments
 (0)