Fix access level for init and other tweaks

Fixes #6
This commit is contained in:
Lars-Jørgen Kristiansen 2018-04-16 16:00:33 +07:00 committed by Sindre Sorhus
parent 3b7f63bc90
commit 3dffe718a2
2 changed files with 8 additions and 6 deletions

View File

@ -1,14 +1,16 @@
// MIT License © Sindre Sorhus // MIT License © Sindre Sorhus
import Cocoa import Foundation
public final class Defaults { public final class Defaults {
public class Keys {} public class Keys {
fileprivate init() {}
}
public final class Key<T: Codable>: Keys { public final class Key<T: Codable>: Keys {
fileprivate let name: String fileprivate let name: String
fileprivate let defaultValue: T fileprivate let defaultValue: T
init(_ key: String, default defaultValue: T) { public init(_ key: String, default defaultValue: T) {
self.name = key self.name = key
self.defaultValue = defaultValue self.defaultValue = defaultValue
} }
@ -17,7 +19,7 @@ public final class Defaults {
public final class OptionalKey<T: Codable>: Keys { public final class OptionalKey<T: Codable>: Keys {
fileprivate let name: String fileprivate let name: String
init(_ key: String) { public init(_ key: String) {
self.name = key self.name = key
} }
} }

View File

@ -1,5 +1,5 @@
import XCTest import XCTest
@testable import Defaults import Defaults
let fixtureUrl = URL(string: "httos://sindresorhus.com")! let fixtureUrl = URL(string: "httos://sindresorhus.com")!
@ -22,7 +22,7 @@ final class DefaultsTests: XCTestCase {
defaults.clear() defaults.clear()
} }
func testKey() { func testKey() {
let key = Defaults.Key<Bool>("key", default: false) let key = Defaults.Key<Bool>("key", default: false)
XCTAssertFalse(UserDefaults.standard[key]) XCTAssertFalse(UserDefaults.standard[key])
UserDefaults.standard[key] = true UserDefaults.standard[key] = true