Fix availability checks for CocoaPods
This commit is contained in:
parent
9ce53eee2e
commit
a82d6728e7
|
@ -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<T: NSSecureCoding>: 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<T: NSSecureCoding>: 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<T: NSSecureCoding>(key: NSSecureCodingKey<T>) -> 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<T: NSSecureCoding>(key: NSSecureCodingOptionalKey<T>) -> 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<T: NSSecureCoding>(_ keys: NSSecureCodingKey<T>..., 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<T: NSSecureCoding>(_ keys: [NSSecureCodingKey<T>], 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<T: NSSecureCoding>(_ keys: NSSecureCodingOptionalKey<T>..., 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<T: NSSecureCoding>(_ keys: [NSSecureCodingOptionalKey<T>], 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<T: NSSecureCoding>(_ 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<T: NSSecureCoding>(_ 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<T: NSSecureCoding>(key: Defaults.NSSecureCodingKey<T>) -> 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<T: NSSecureCoding>(key: Defaults.NSSecureCodingOptionalKey<T>) -> T? {
|
||||
get { _get(key.name) }
|
||||
set {
|
||||
|
|
|
@ -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<T: NSSecureCoding>(_ 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<T: NSSecureCoding> {
|
||||
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<T: NSSecureCoding> {
|
||||
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<T: NSSecureCoding>(
|
||||
_ key: Defaults.NSSecureCodingKey<T>,
|
||||
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<T: NSSecureCoding>(
|
||||
_ key: Defaults.NSSecureCodingOptionalKey<T>,
|
||||
options: NSKeyValueObservingOptions = [.initial, .old, .new],
|
||||
|
|
|
@ -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>("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<ExamplePersistentHistory>("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<ExamplePersistentHistory>("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<ExamplePersistentHistory>("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<ExamplePersistentHistory>("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<ExamplePersistentHistory>("optionalKey3")
|
||||
Defaults[key3] = ExamplePersistentHistory(value: newString3)
|
||||
Defaults.reset(key3)
|
||||
|
|
Loading…
Reference in New Issue