Skip to content

Commit a965217

Browse files
removeObject 추가
1 parent 1480919 commit a965217

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

WTUserDefaults/WTUserDefaultsHelper.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ public class WTUserDefaultsHelper : WTUserDefaultsProtocol {
4747
public func synchronize() {
4848
userDefaults.synchronize()
4949
}
50+
51+
public func removeObject(forKey key: String) {
52+
userDefaults.removeObject(forKey: key)
53+
}
5054
}

WTUserDefaults/WTUserDefaultsProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public protocol WTUserDefaultsProtocol {
1616
func getObject(forKey: String) -> Any?
1717
func getArray(forKey: String) -> [Any]?
1818
func set(_ value:Any, forKey: String)
19+
func removeObject(forKey key: String)
1920
func synchronize()
2021
}

WTUserDefaultsTests/WTUserDefaultsTests.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ class WTUserDefaultsTests: XCTestCase {
8787
ret = defaults.getArray(forKey: stringKey) as? [String]
8888
XCTAssert(4 == ret?.count)
8989
XCTAssert("!@#" == ret?[3])
90-
90+
}
91+
92+
func testRemoveObject() {
93+
guard let defaults = userDefaults else { return }
94+
let stringKey = "ABC", value = "Value"
95+
defaults.set(value, forKey: stringKey)
96+
guard let ret = defaults.getObject(forKey: stringKey) as? String else { return XCTFail() }
97+
XCTAssert(ret == value)
98+
userDefaults?.removeObject(forKey: stringKey)
99+
guard nil == defaults.getObject(forKey: stringKey) as? String else { return XCTFail() }
91100
}
92101

93102
}

0 commit comments

Comments
 (0)