Closed BB9z closed 1 year ago
This PR allows us to define the key in a more comfortable way:
extension DefaultsKeys { // Before var username: DefaultsKey<String?> { .init("username") } // After var username: DefaultsKey<String?> { .init() } }
I am not sure about the best way to add test cases to the existing system. Instead, I run this test locally.
import XCTest @testable import SwiftyUserDefaults extension DefaultsKeys { var username: DefaultsKey<String?> { .init() } var launchCount: DefaultsKey<Int> { .init(defaultValue: 0) } var hotkeyEnabled: DefaultsKey<Bool> { .init("hotkey", defaultValue: true) } } class MyTest: XCTestCase { func testKeys() { let ud = UserDefaults.standard Defaults.username = nil XCTAssertNil(ud.string(forKey: "username")) Defaults.username = "foo" XCTAssertEqual("foo", ud.string(forKey: "username")) Defaults.launchCount = 20 XCTAssertEqual(20, ud.integer(forKey: "launchCount")) Defaults.removeAll() XCTAssertEqual(0, ud.integer(forKey: "launchCount")) XCTAssertTrue(Defaults.hotkeyEnabled) Defaults.hotkeyEnabled = false XCTAssertEqual(NSNumber(value: false), ud.object(forKey: "hotkey") as? NSNumber) } }
Generated by :no_entry_sign: Danger Swift against 3ef365abad0cdea573a888f2e0425bf6d30d68d2
This PR allows us to define the key in a more comfortable way:
I am not sure about the best way to add test cases to the existing system. Instead, I run this test locally.