diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 620e08b..f252955 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -5,12 +5,12 @@ public final class Defaults { public class Keys { public typealias Key = Defaults.Key - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public typealias NSSecureCodingKey = Defaults.NSSecureCodingKey public typealias OptionalKey = Defaults.OptionalKey - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public typealias NSSecureCodingOptionalKey = Defaults.NSSecureCodingOptionalKey fileprivate init() {} @@ -38,7 +38,7 @@ public final class Defaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public final class NSSecureCodingKey: Keys { public let name: String public let defaultValue: T @@ -72,7 +72,7 @@ public final class Defaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public final class NSSecureCodingOptionalKey: Keys { public let name: String public let suite: UserDefaults @@ -95,7 +95,7 @@ public final class Defaults { } /// Access a defaults value using a `Defaults.NSSecureCodingKey`. - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static subscript(key: NSSecureCodingKey) -> T { get { key.suite[key] } set { @@ -112,7 +112,7 @@ public final class Defaults { } /// Access a defaults value using a `Defaults.OptionalKey`. - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static subscript(key: NSSecureCodingOptionalKey) -> T? { get { key.suite[key] } set { @@ -150,7 +150,7 @@ public final class Defaults { - Parameter keys: Keys to reset. - Parameter suite: `UserDefaults` suite. */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func reset(_ keys: NSSecureCodingKey..., suite: UserDefaults = .standard) { reset(keys, suite: suite) } @@ -187,7 +187,7 @@ public final class Defaults { - Parameter keys: Keys to reset. - Parameter suite: `UserDefaults` suite. */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func reset(_ keys: [NSSecureCodingKey], suite: UserDefaults = .standard) { for key in keys { key.suite[key] = key.defaultValue @@ -224,7 +224,7 @@ public final class Defaults { - Parameter suite: `UserDefaults` suite. ``` */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func reset(_ keys: NSSecureCodingOptionalKey..., suite: UserDefaults = .standard) { reset(keys, suite: suite) } @@ -260,7 +260,7 @@ public final class Defaults { - Parameter keys: Keys to reset. - Parameter suite: `UserDefaults` suite. */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func reset(_ keys: [NSSecureCodingOptionalKey], suite: UserDefaults = .standard) { for key in keys { key.suite[key] = nil @@ -299,7 +299,7 @@ extension UserDefaults { return nil } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) private func _get(_ key: String) -> T? { if UserDefaults.isNativelySupportedType(T.self) { return object(forKey: key) as? T @@ -342,7 +342,7 @@ extension UserDefaults { set(_encode(value), forKey: key) } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) private func _set(_ key: String, to value: T) { if UserDefaults.isNativelySupportedType(T.self) { set(value, forKey: key) @@ -359,7 +359,7 @@ extension UserDefaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public subscript(key: Defaults.NSSecureCodingKey) -> T { get { _get(key.name) ?? key.defaultValue } set { @@ -379,7 +379,7 @@ extension UserDefaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public subscript(key: Defaults.NSSecureCodingOptionalKey) -> T? { get { _get(key.name) } set { diff --git a/Sources/Defaults/Observation.swift b/Sources/Defaults/Observation.swift index 365fb0c..bb653b1 100644 --- a/Sources/Defaults/Observation.swift +++ b/Sources/Defaults/Observation.swift @@ -43,7 +43,7 @@ extension Defaults { return [T].init(jsonString: "\([value])")?.first } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) private static func deserialize(_ value: Any?, to type: T.Type) -> T? { guard let value = value, @@ -96,7 +96,7 @@ extension Defaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public struct NSSecureCodingKeyChange { public let kind: NSKeyValueChange public let indexes: IndexSet? @@ -129,7 +129,7 @@ extension Defaults { } } - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public struct NSSecureCodingOptionalKeyChange { public let kind: NSKeyValueChange public let indexes: IndexSet? @@ -240,7 +240,7 @@ extension Defaults { /** Observe a defaults key. */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func observe( _ key: Defaults.NSSecureCodingKey, options: NSKeyValueObservingOptions = [.initial, .old, .new], @@ -286,7 +286,7 @@ extension Defaults { /** Observe an optional defaults key. */ - @available(iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) public static func observe( _ key: Defaults.NSSecureCodingOptionalKey, options: NSKeyValueObservingOptions = [.initial, .old, .new], diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index 1f77495..4638653 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -14,7 +14,7 @@ enum FixtureEnum: String, Codable { let fixtureDate = Date() -@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) +@available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) final class ExamplePersistentHistory: NSPersistentHistoryToken { let value: String @@ -46,9 +46,9 @@ extension Defaults.Keys { static let date = Key("date", default: fixtureDate) // NSSecureCoding - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) static let persistentHistoryValue = ExamplePersistentHistory(value: "ExampleToken") - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) static let persistentHistory = NSSecureCodingKey("persistentHistory", default: persistentHistoryValue) } @@ -106,7 +106,7 @@ final class DefaultsTests: XCTestCase { XCTAssertTrue(Defaults[.key]) } - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) func testNSSecureCodingKeys() { XCTAssertEqual(Defaults.Keys.persistentHistoryValue.value, Defaults[.persistentHistory].value) let newPersistentHistory = ExamplePersistentHistory(value: "NewValue") @@ -182,7 +182,7 @@ final class DefaultsTests: XCTestCase { waitForExpectations(timeout: 10) } - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) func testObserveNSSecureCodingKey() { let key = Defaults.NSSecureCodingKey("observeNSSecureCodingKey", default: ExamplePersistentHistory(value: "TestValue")) let expect = expectation(description: "Observation closure being called") @@ -217,7 +217,7 @@ final class DefaultsTests: XCTestCase { waitForExpectations(timeout: 10) } - @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) + @available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) func testObserveNSSecureCodingOptionalKey() { let key = Defaults.NSSecureCodingOptionalKey("observeNSSecureCodingOptionalKey") let expect = expectation(description: "Observation closure being called") @@ -286,7 +286,7 @@ final class DefaultsTests: XCTestCase { XCTAssertEqual(Defaults[key1], defaultString1) XCTAssertEqual(Defaults[key2], newString2) - if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) { + if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) { let key3 = Defaults.NSSecureCodingKey("key3", default: ExamplePersistentHistory(value: defaultString3)) Defaults[key3] = ExamplePersistentHistory(value: newString3) Defaults.reset(key3) @@ -326,7 +326,7 @@ final class DefaultsTests: XCTestCase { XCTAssertEqual(Defaults[key1], nil) XCTAssertEqual(Defaults[key2], newString2) - if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) { + if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, iOSApplicationExtension 11.0, macOSApplicationExtension 10.13, tvOSApplicationExtension 11.0, watchOSApplicationExtension 4.0, *) { let key3 = Defaults.NSSecureCodingOptionalKey("optionalKey3") Defaults[key3] = ExamplePersistentHistory(value: newString3) Defaults.reset(key3)