Skip to content

Commit 2516b1a

Browse files
committed
Update to swift 6
Use actor for Prephirences
1 parent 3bc9e04 commit 2516b1a

File tree

8 files changed

+65
-30
lines changed

8 files changed

+65
-30
lines changed

Package.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// swift-tools-version:5.5
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
55

66
let package = Package(
77
name: "Prephirences",
88
platforms: [
9-
.macOS(.v10_11),
10-
.iOS(.v9),
11-
.tvOS(.v9),
12-
.watchOS(.v3)
9+
.macOS(.v10_13),
10+
.iOS(.v12),
11+
.tvOS(.v12),
12+
.watchOS(.v4)
1313
],
1414
products: [
1515
.library(
@@ -24,7 +24,10 @@ let package = Package(
2424
.testTarget(
2525
name: "PrephirencesTests",
2626
dependencies: ["Prephirences"],
27-
path: "Tests")
27+
path: "Tests",
28+
resources: [
29+
.process("Test.plist")
30+
])
2831
],
29-
swiftLanguageVersions: [.v5]
32+
swiftLanguageModes: [.v6]
3033
)

[email protected]

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// swift-tools-version:5.5
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: "Prephirences",
8+
platforms: [
9+
.macOS(.v10_11),
10+
.iOS(.v9),
11+
.tvOS(.v9),
12+
.watchOS(.v3)
13+
],
14+
products: [
15+
.library(
16+
name: "Prephirences",
17+
targets: ["Prephirences"])
18+
],
19+
targets: [
20+
.target(
21+
name: "Prephirences",
22+
dependencies: [],
23+
path: "Sources"),
24+
.testTarget(
25+
name: "PrephirencesTests",
26+
dependencies: ["Prephirences"],
27+
path: "Tests")
28+
],
29+
swiftLanguageVersions: [.v5]
30+
)

Sources/KeychainPreferences.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class KeychainPreferences: PreferencesAdapter {
3737
// MARK: constantes
3838

3939
/// Shared instance. service is equal to bundle identifier.
40-
public static var sharedInstance = KeychainPreferences(service: Bundle.main.bundleIdentifier ?? "Prephirences")
40+
nonisolated(unsafe) public static var sharedInstance = KeychainPreferences(service: Bundle.main.bundleIdentifier ?? "Prephirences")
4141

4242
/// Class Constants
4343
static let klass = String(kSecClass)
@@ -55,8 +55,8 @@ open class KeychainPreferences: PreferencesAdapter {
5555
static let limit = String(kSecMatchLimit)
5656

5757
struct Limit {
58-
static let one = kSecMatchLimitOne
59-
static let all = kSecMatchLimitAll
58+
static let one = String(kSecMatchLimitOne)
59+
static let all = String(kSecMatchLimitAll)
6060
}
6161
}
6262

@@ -265,7 +265,7 @@ open class KeychainPreferences: PreferencesAdapter {
265265
query[Return.data] = kCFBooleanTrue
266266
query[Return.persistentRef] = kCFBooleanTrue
267267
query[Return.ref] = kCFBooleanTrue
268-
query[Match.limit] = Match.Limit.one
268+
query[Match.limit] = Match.Limit.one as CFString
269269

270270
var result: AnyObject?
271271
let status = SecItemCopyMatching(query as CFDictionary, &result)
@@ -321,7 +321,7 @@ extension KeychainPreferences: MutablePreferencesType {
321321
var query: [String: Any] = newQuery()
322322
query[Attribute.account] = key
323323
query[Return.data] = kCFBooleanTrue
324-
query[Match.limit] = Match.Limit.one
324+
query[Match.limit] = Match.Limit.one as CFString
325325

326326
var result: AnyObject?
327327
let status = SecItemCopyMatching(query as CFDictionary, &result)
@@ -335,7 +335,7 @@ extension KeychainPreferences: MutablePreferencesType {
335335
public func keys() -> [String] {
336336
var query: [String: Any] = newQuery()
337337
query[Return.attributes] = kCFBooleanTrue
338-
query[Match.limit] = Match.Limit.all
338+
query[Match.limit] = Match.Limit.all as CFString
339339

340340
var result: AnyObject?
341341
let status = SecItemCopyMatching(query as CFDictionary, &result)
@@ -354,7 +354,7 @@ extension KeychainPreferences: MutablePreferencesType {
354354
#if os(iOS) || os(watchOS) || os(tvOS)
355355
query[Return.data] = kCFBooleanTrue
356356
#endif
357-
query[Match.limit] = Match.Limit.all
357+
query[Match.limit] = Match.Limit.all as CFString
358358

359359
var result: AnyObject?
360360
let status = SecItemCopyMatching(query as CFDictionary, &result)
@@ -448,7 +448,7 @@ extension KeychainPreferences: MutablePreferencesType {
448448
public func clearAll() {
449449
var query: [String: Any] = newQuery()
450450
#if !os(iOS) && !os(watchOS) && !os(tvOS)
451-
query[Match.limit] = Match.Limit.all
451+
query[Match.limit] = Match.Limit.all as CFString
452452
#endif
453453
delete(query: query)
454454
}

Sources/PatternPreferences.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ open class CompositePreferences: ExpressibleByArrayLiteral {
4242

4343
// MARK: singleton
4444
/// Shared instance.
45-
static let sharedInstance = CompositePreferences([])
45+
nonisolated(unsafe) static let sharedInstance = CompositePreferences([])
4646

4747
// MARK: init
4848
/// Initialize using an array of `PreferencesType`.

Sources/PreferencesController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ open class PreferencesKVCHelper: NSObject { // NSKeyValueCoding
5353
import AppKit
5454

5555
@objc(PreferencesController)
56-
public class PreferencesController: NSController {
56+
public class PreferencesController: NSController, @unchecked Sendable {
5757

5858
public var values = PreferencesKVCHelper(preferences: nil)
5959

Sources/Prephirences.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SOFTWARE.
2828
import Foundation
2929

3030
/* Preferences manager class that contains some Preferences */
31-
open class Prephirences {
31+
public actor Prephirences {
3232

3333
/** Shared preferences. Could be replaced by any other preferences */
3434
public static var sharedInstance: PreferencesType = MutableDictionaryPreferences()
@@ -42,7 +42,7 @@ open class Prephirences {
4242
fileprivate static var _instances = [PrephirencesKey: PreferencesType]()
4343

4444
/* Get Preferences for PrephirencesKey */
45-
fileprivate class func instance(forKey key: PrephirencesKey, orRegister newOne: PreferencesType? = nil) -> PreferencesType? {
45+
fileprivate static func instance(forKey key: PrephirencesKey, orRegister newOne: PreferencesType? = nil) -> PreferencesType? {
4646
if let value = self._instances[key] {
4747
return value
4848
} else if let toRegister = newOne {
@@ -51,24 +51,24 @@ open class Prephirences {
5151
return newOne
5252
}
5353
/* Add Preferences for PrephirencesKey */
54-
fileprivate class func register(preferences: PreferencesType, forKey key: PrephirencesKey) {
54+
fileprivate static func register(preferences: PreferencesType, forKey key: PrephirencesKey) {
5555
self._instances[key] = preferences
5656
}
5757
/* Remove Preferences for PrephirencesKey */
58-
fileprivate class func unregisterPreferences(forKey key: PrephirencesKey) -> PreferencesType? {
58+
fileprivate static func unregisterPreferences(forKey key: PrephirencesKey) -> PreferencesType? {
5959
return self._instances.removeValue(forKey: key)
6060
}
6161

6262
/* Get Preferences for key */
63-
open class func instance<Key: Hashable>(forKey key: Key, orRegister newOne: PreferencesType? = nil) -> PreferencesType? {
63+
public static func instance<Key: Hashable>(forKey key: Key, orRegister newOne: PreferencesType? = nil) -> PreferencesType? {
6464
return self.instance(forKey: PrephirencesKey(key), orRegister: newOne)
6565
}
6666
/* Add Preferences for key */
67-
open class func registerInstance<Key: Hashable>(_ preferences: PreferencesType, forKey key: Key) {
67+
public static func registerInstance<Key: Hashable>(_ preferences: PreferencesType, forKey key: Key) {
6868
self.register(preferences: preferences, forKey: PrephirencesKey(key))
6969
}
7070
/* Remove Preferences for key */
71-
open class func unregisterInstance<Key: Hashable>(forKey key: Key) -> PreferencesType? {
71+
public static func unregisterInstance<Key: Hashable>(forKey key: Key) -> PreferencesType? {
7272
return self.unregisterPreferences(forKey: PrephirencesKey(key))
7373
}
7474

Sources/UserDefaults/UserDefaults+Adds.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public extension Foundation.UserDefaults {
108108
}
109109

110110
// MARK: Global shortcut
111-
public var UserDefaultsKeySeparator = "."
111+
nonisolated(unsafe) public var UserDefaultsKeySeparator = "."
112112

113113
#if os(OSX)
114114
import AppKit
115-
public var UserDefaultsController = NSUserDefaultsController.shared
115+
nonisolated(unsafe) public var UserDefaultsController = NSUserDefaultsController.shared
116116

117117
// http://stackoverflow.com/questions/29312106/xcode-6-os-x-storyboard-multiple-user-defaults-controllers-bug-with-multiple-sce/29509031#29509031
118118
@objc(SharedUserDefaultsControllerProxy)

Tests/PrephirencesTests.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class PrephirencesTests: XCTestCase {
6666
}*/
6767

6868
func testFromFile() {
69-
if let filePath = path(forResource: "Test", ofType: "plist", in: Bundle(for: type(of: self))) {
69+
if let filePath = path(forResource: "Test", ofType: "plist", in: Bundle(for: type(of: self)))
70+
?? path(forResource: "Test", ofType: "plist", in: Bundle.module) {
7071
if let preference = DictionaryPreferences(filePath: filePath) {
7172
for (key,value) in preference.dictionary() {
7273
print("\(key)=\(value)")
@@ -79,8 +80,9 @@ class PrephirencesTests: XCTestCase {
7980
XCTFail("Failed to get file url")
8081
}
8182

82-
if let preference = DictionaryPreferences(filename: "Test", ofType: "plist", bundle: Bundle(for: type(of: self))) ??
83-
DictionaryPreferences(filePath: "Tests/Test.plist") {
83+
if let preference = DictionaryPreferences(filename: "Test", ofType: "plist", bundle: Bundle(for: type(of: self)))
84+
?? DictionaryPreferences(filename: "Test", ofType: "plist", bundle: Bundle.module)
85+
?? DictionaryPreferences(filePath: "Tests/Test.plist") {
8486
for (key,value) in preference.dictionary() {
8587
print("\(key)=\(value)")
8688
}
@@ -726,7 +728,7 @@ public struct MyStruct: Prephirencable {
726728
public static let stringValueLoaded: String? = instance["stringValueLoaded"] as? String
727729

728730
public struct MySubLevel: Prephirencable { // swiftlint:disable:this nesting
729-
public static let parent = MyStruct.instance
731+
nonisolated(unsafe) public static let parent = MyStruct.instance
730732

731733
public static let boolValue: Bool = instance["boolValue"] as? Bool ?? false
732734
public static let integer: Int? = instance["integer"] as? Int

0 commit comments

Comments
 (0)