From 3b7f63bc903732a94324473e3c721b22688fcfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars-J=C3=B8rgen=20Kristiansen?= Date: Sun, 15 Apr 2018 20:09:53 +0200 Subject: [PATCH] Use native data coding (#5) --- Sources/Defaults/Defaults.swift | 3 ++- Tests/DefaultsTests/DefaultsTests.swift | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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])