diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 0fc821b..0d8807a 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -115,7 +115,8 @@ public extension UserDefaults { is Int.Type, is Double.Type, is Float.Type, - is Date.Type: + is Date.Type, + is Data.Type: return true default: return false diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index fa80a3a..78fff7e 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -13,6 +13,7 @@ extension Defaults.Keys { static let key = Defaults.Key("key", default: false) static let url = Defaults.Key("url", default: fixtureUrl) static let `enum` = Defaults.Key("enum", default: .oneHour) + static let data = Defaults.Key("data", default: Data(bytes: [])) } final class DefaultsTests: XCTestCase { @@ -53,6 +54,14 @@ final class DefaultsTests: XCTestCase { XCTAssertEqual(defaults[.enum], FixtureEnum.oneHour) } + func testDataType() { + XCTAssertEqual(defaults[.data], Data(bytes: [])) + + let newData = Data(bytes: [0xFF]) + defaults[.data] = newData + XCTAssertEqual(defaults[.data], newData) + } + func testClear() { defaults[.key] = true XCTAssertTrue(defaults[.key])