Tests/OrgAppTests/TestDefaults.swift

29b57626b6e9757f773ad01c0bf814d1a32df160
orgstar/Tests/OrgAppTests/TestDefaults.swift

20 lines · 747 bytes

 1import Foundation
 2
 3/// A defaults suite named `<prefix>-<UUID>`, kept in the temporary folder rather than
 4/// `~/Library/Preferences` and removed with its plist when released. cfprefsd may write a
 5/// plist again after it is removed, so the suite is a path outside the preferences folder.
 6final class TestDefaults: UserDefaults, @unchecked Sendable {
 7    let name: String
 8    private let path: String
 9
10    init(_ prefix: String) {
11        name = "\(prefix)-\(UUID().uuidString)"
12        path = FileManager.default.temporaryDirectory.appendingPathComponent(name).path
13        super.init(suiteName: path)!
14    }
15
16    deinit {
17        removePersistentDomain(forName: path)
18        try? FileManager.default.removeItem(atPath: path + ".plist")
19    }
20}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form