diff --git a/README.md b/README.md index 24379fd..92a6abb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift. -Provides a defaultKeychainWrapper() function to access singleton instance that is setup to work for most needs. +Provides singleton instance that is setup to work for most needs. Use KeychainWrapper.standard to access the singleton instance. If you need to customize the keychain access to use a custom identifier or access group, you can create your own instance instead of using the singleton access. @@ -14,17 +14,17 @@ Users that want to deviate from this default implementation, now can do so in in Add a string value to keychain: ``` -let saveSuccessful: Bool = KeychainWrapper.defaultKeychainWrapper.set("Some String", forKey: "myKey") +let saveSuccessful: Bool = KeychainWrapper.standard.set("Some String", forKey: "myKey") ``` Retrieve a string value from keychain: ``` -let retrievedString: String? = KeychainWrapper.defaultKeychainWrapper.string(forKey: "myKey") +let retrievedString: String? = KeychainWrapper.standard.string(forKey: "myKey") ``` Remove a string value from keychain: ``` -let removeSuccessful: Bool = KeychainWrapper.defaultKeychainWrapper.remove(key: "myKey") +let removeSuccessful: Bool = KeychainWrapper.standard.remove(key: "myKey") ``` ##Custom Instance @@ -55,7 +55,7 @@ let removeSuccessful: Bool = customKeychainWrapperInstance.remove(key: "myKey") By default, all items saved to keychain can only be accessed when the device is unlocked. To change this accessibility, an optional "withAccessibility" param can be set on all requests. The enum KeychainItemAccessibilty provides an easy way to select the accessibility level desired: ``` -KeychainWrapper.defaultKeychainWrapper.set("Some String", forKey: "myKey", withAccessibility: .AfterFirstUnlock) +KeychainWrapper.standard.set("Some String", forKey: "myKey", withAccessibility: .AfterFirstUnlock) ``` ##Installation @@ -84,6 +84,8 @@ Download and drop ```KeychainWrapper.swift``` and ```KeychainItemAcessibility.sw ## Release History +* 2.2.1 + * Syntax updates to be more Swift 3 like * 2.2 * Updated to support Swift 3.0 * Remove deprecated functions (static access) diff --git a/SwiftKeychainWrapper.podspec b/SwiftKeychainWrapper.podspec index 59699a6..2b22e98 100644 --- a/SwiftKeychainWrapper.podspec +++ b/SwiftKeychainWrapper.podspec @@ -1,9 +1,9 @@ Pod::Spec.new do |s| s.name = 'SwiftKeychainWrapper' - s.version = '2.2.0' + s.version = '2.2.1' s.summary = 'Wrapper for the iOS Keychain written in Swift.' s.description = <<-DESC - A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to NSUserDefaults. Supports Access Groups. Written in Swift.' + A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to UserDefaults. Supports Access Groups. Written in Swift.' DESC s.module_name = "SwiftKeychainWrapper" s.homepage = 'https://github.com/jrendel/SwiftKeychainWrapper' diff --git a/SwiftKeychainWrapper/Info.plist b/SwiftKeychainWrapper/Info.plist index 0f3a86e..c8b04b8 100644 --- a/SwiftKeychainWrapper/Info.plist +++ b/SwiftKeychainWrapper/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.2.0 + 2.2.1 CFBundleSignature ???? CFBundleVersion - 2.2.0 + 2.2.1 NSPrincipalClass diff --git a/SwiftKeychainWrapper/KeychainWrapper.swift b/SwiftKeychainWrapper/KeychainWrapper.swift index 0fe555f..b8a4efa 100644 --- a/SwiftKeychainWrapper/KeychainWrapper.swift +++ b/SwiftKeychainWrapper/KeychainWrapper.swift @@ -42,8 +42,12 @@ private let SecReturnAttributes: String = kSecReturnAttributes as String /// KeychainWrapper is a class to help make Keychain access in Swift more straightforward. It is designed to make accessing the Keychain services more like using NSUserDefaults, which is much more familiar to people. open class KeychainWrapper { + + @available(*, deprecated: 2.2.1, message: "KeychainWrapper.defaultKeychainWrapper is deprecated, use KeychainWrapper.standard instead") + public static let defaultKeychainWrapper = KeychainWrapper.standard + /// Default keychain wrapper access - public static let defaultKeychainWrapper = KeychainWrapper() + public static let standard = KeychainWrapper() /// ServiceName is used for the kSecAttrService property to uniquely identify this keychain accessor. If no service name is specified, KeychainWrapper will default to using the bundleIdentifier. private (set) public var serviceName: String @@ -293,13 +297,17 @@ open class KeychainWrapper { } } - + @available(*, deprecated: 2.2.1, message: "remove is deprecated, use removeObject instead") + @discardableResult open func remove(key: String, withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool { + return removeObject(forKey: key, withAccessibility: accessibility) + } + /// Remove an object associated with a specified key. If re-using a key but with a different accessibility, first remove the previous key value using removeObjectForKey(:withAccessibility) using the same accessibilty it was saved with. /// /// - parameter forKey: The key value to remove data for. /// - parameter withAccessibility: Optional accessibility level to use when looking up the keychain item. /// - returns: True if successful, false otherwise. - @discardableResult open func remove(key: String, withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool { + @discardableResult open func removeObject(forKey key: String, withAccessibility accessibility: KeychainItemAccessibility? = nil) -> Bool { let keychainQueryDictionary: [String:Any] = setupKeychainQueryDictionary(forKey: key, withAccessibility: accessibility) // Delete diff --git a/SwiftKeychainWrapperTests/KeychainWrapperDefaultWrapperTests.swift b/SwiftKeychainWrapperTests/KeychainWrapperDefaultWrapperTests.swift index 133cad8..3604055 100644 --- a/SwiftKeychainWrapperTests/KeychainWrapperDefaultWrapperTests.swift +++ b/SwiftKeychainWrapperTests/KeychainWrapperDefaultWrapperTests.swift @@ -25,8 +25,8 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey2) + KeychainWrapper.standard.removeObject(forKey: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey2) super.tearDown() } @@ -34,47 +34,47 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { func testDefaultServiceName() { let bundleIdentifier = Bundle.main.bundleIdentifier if let bundleIdentifierString = bundleIdentifier { - XCTAssertEqual(KeychainWrapper.defaultKeychainWrapper.serviceName, bundleIdentifierString, "Service Name should be equal to the bundle identifier when it is accessible") + XCTAssertEqual(KeychainWrapper.standard.serviceName, bundleIdentifierString, "Service Name should be equal to the bundle identifier when it is accessible") } else { - XCTAssertEqual(KeychainWrapper.defaultKeychainWrapper.serviceName, "SwiftKeychainWrapper", "Service Name should be equal to SwiftKeychainWrapper when the bundle identifier is not accessible") + XCTAssertEqual(KeychainWrapper.standard.serviceName, "SwiftKeychainWrapper", "Service Name should be equal to SwiftKeychainWrapper when the bundle identifier is not accessible") } } func testDefaultAccessGroup() { - XCTAssertNil(KeychainWrapper.defaultKeychainWrapper.accessGroup, "Access Group should be nil when nothing is set") + XCTAssertNil(KeychainWrapper.standard.accessGroup, "Access Group should be nil when nothing is set") } func testHasValueForKey() { - XCTAssertFalse(KeychainWrapper.defaultKeychainWrapper.hasValue(forKey: testKey), "Keychain should not have a value for the test key") + XCTAssertFalse(KeychainWrapper.standard.hasValue(forKey: testKey), "Keychain should not have a value for the test key") - KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + KeychainWrapper.standard.set(testString, forKey: testKey) - XCTAssertTrue(KeychainWrapper.defaultKeychainWrapper.hasValue(forKey: testKey), "Keychain should have a value for the test key after it is set") + XCTAssertTrue(KeychainWrapper.standard.hasValue(forKey: testKey), "Keychain should have a value for the test key after it is set") } func testRemoveObjectFromKeychain() { - KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + KeychainWrapper.standard.set(testString, forKey: testKey) - XCTAssertTrue(KeychainWrapper.defaultKeychainWrapper.hasValue(forKey: testKey), "Keychain should have a value for the test key after it is set") + XCTAssertTrue(KeychainWrapper.standard.hasValue(forKey: testKey), "Keychain should have a value for the test key after it is set") - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) - XCTAssertFalse(KeychainWrapper.defaultKeychainWrapper.hasValue(forKey: testKey), "Keychain should not have a value for the test key after it is removed") + XCTAssertFalse(KeychainWrapper.standard.hasValue(forKey: testKey), "Keychain should not have a value for the test key after it is removed") } func testStringSave() { - let stringSaved = KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + let stringSaved = KeychainWrapper.standard.set(testString, forKey: testKey) XCTAssertTrue(stringSaved, "String did not save to Keychain") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testStringRetrieval() { - KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + KeychainWrapper.standard.set(testString, forKey: testKey) - if let retrievedString = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) { + if let retrievedString = KeychainWrapper.standard.string(forKey: testKey) { XCTAssertEqual(retrievedString, testString, "String retrieved for key should equal string saved for key") } else { XCTFail("String for Key not found") @@ -82,26 +82,26 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { } func testStringRetrievalWhenValueDoesNotExist() { - let retrievedString = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) + let retrievedString = KeychainWrapper.standard.string(forKey: testKey) XCTAssertNil(retrievedString, "String for Key should not exist") } func testMultipleStringSave() { - if !KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) { + if !KeychainWrapper.standard.set(testString, forKey: testKey) { XCTFail("String for testKey did not save") } - if !KeychainWrapper.defaultKeychainWrapper.set(testString2, forKey: testKey2) { + if !KeychainWrapper.standard.set(testString2, forKey: testKey2) { XCTFail("String for testKey2 did not save") } - if let string1Retrieved = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) { + if let string1Retrieved = KeychainWrapper.standard.string(forKey: testKey) { XCTAssertEqual(string1Retrieved, testString, "String retrieved for testKey should match string saved to testKey") } else { XCTFail("String for testKey could not be retrieved") } - if let string2Retrieved = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey2) { + if let string2Retrieved = KeychainWrapper.standard.string(forKey: testKey2) { XCTAssertEqual(string2Retrieved, testString2, "String retrieved for testKey2 should match string saved to testKey2") } else { XCTFail("String for testKey2 could not be retrieved") @@ -110,21 +110,21 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { func testMultipleStringsSavedToSameKey() { - if !KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) { + if !KeychainWrapper.standard.set(testString, forKey: testKey) { XCTFail("String for testKey did not save") } - if let string1Retrieved = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) { + if let string1Retrieved = KeychainWrapper.standard.string(forKey: testKey) { XCTAssertEqual(string1Retrieved, testString, "String retrieved for testKey after first save should match first string saved testKey") } else { XCTFail("String for testKey could not be retrieved") } - if !KeychainWrapper.defaultKeychainWrapper.set(testString2, forKey: testKey) { + if !KeychainWrapper.standard.set(testString2, forKey: testKey) { XCTFail("String for testKey did not update") } - if let string2Retrieved = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) { + if let string2Retrieved = KeychainWrapper.standard.string(forKey: testKey) { XCTAssertEqual(string2Retrieved, testString2, "String retrieved for testKey after update should match second string saved to testKey") } else { XCTFail("String for testKey could not be retrieved after update") @@ -133,7 +133,7 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { func testNSCodingObjectSave() { let myTestObject = TestObject() - let objectSaved = KeychainWrapper.defaultKeychainWrapper.set(myTestObject, forKey: testKey) + let objectSaved = KeychainWrapper.standard.set(myTestObject, forKey: testKey) XCTAssertTrue(objectSaved, "Object that implements NSCoding should save to Keychain") } @@ -144,9 +144,9 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { myTestObject.objectName = testString myTestObject.objectRating = testInt - KeychainWrapper.defaultKeychainWrapper.set(myTestObject, forKey: testKey) + KeychainWrapper.standard.set(myTestObject, forKey: testKey) - if let retrievedObject = KeychainWrapper.defaultKeychainWrapper.object(forKey: testKey) as? TestObject{ + if let retrievedObject = KeychainWrapper.standard.object(forKey: testKey) as? TestObject{ XCTAssertEqual(retrievedObject.objectName, testString, "NSCoding compliant object retrieved for key should have objectName property equal to what it was stored with") XCTAssertEqual(retrievedObject.objectRating, testInt, "NSCoding compliant object retrieved for key should have objectRating property equal to what it was stored with") } else { @@ -155,7 +155,7 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { } func testNSCodingObjectRetrievalWhenValueDoesNotExist() { - let retrievedObject = KeychainWrapper.defaultKeychainWrapper.object(forKey: testKey) as? TestObject + let retrievedObject = KeychainWrapper.standard.object(forKey: testKey) as? TestObject XCTAssertNil(retrievedObject, "Object for Key should not exist") } @@ -163,7 +163,7 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { let testData = testString.data(using: String.Encoding.utf8) if let data = testData { - let dataSaved = KeychainWrapper.defaultKeychainWrapper.set(data, forKey: testKey) + let dataSaved = KeychainWrapper.standard.set(data, forKey: testKey) XCTAssertTrue(dataSaved, "Data did not save to Keychain") } else { @@ -177,14 +177,14 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { return } - KeychainWrapper.defaultKeychainWrapper.set(testData, forKey: testKey) + KeychainWrapper.standard.set(testData, forKey: testKey) - guard let retrievedData = KeychainWrapper.defaultKeychainWrapper.data(forKey: testKey) else { + guard let retrievedData = KeychainWrapper.standard.data(forKey: testKey) else { XCTFail("Data for Key not found") return } - if KeychainWrapper.defaultKeychainWrapper.dataRef(forKey: testKey) == nil { + if KeychainWrapper.standard.dataRef(forKey: testKey) == nil { XCTFail("Data references for Key not found") } @@ -196,10 +196,10 @@ class KeychainWrapperDefaultWrapperTests: XCTestCase { } func testDataRetrievalWhenValueDoesNotExist() { - let retrievedData = KeychainWrapper.defaultKeychainWrapper.data(forKey: testKey) + let retrievedData = KeychainWrapper.standard.data(forKey: testKey) XCTAssertNil(retrievedData, "Data for Key should not exist") - let retrievedDataRef = KeychainWrapper.defaultKeychainWrapper.dataRef(forKey: testKey) + let retrievedDataRef = KeychainWrapper.standard.dataRef(forKey: testKey) XCTAssertNil(retrievedDataRef, "Data ref for Key should not exist") } } diff --git a/SwiftKeychainWrapperTests/KeychainWrapperDeleteTests.swift b/SwiftKeychainWrapperTests/KeychainWrapperDeleteTests.swift index 0c8fde4..bf36115 100644 --- a/SwiftKeychainWrapperTests/KeychainWrapperDeleteTests.swift +++ b/SwiftKeychainWrapperTests/KeychainWrapperDeleteTests.swift @@ -25,24 +25,24 @@ class KeychainWrapperDeleteTests: XCTestCase { func testRemoveAllKeysDeletesSpecificKey() { // save a value we can test delete on - let stringSaved = KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + let stringSaved = KeychainWrapper.standard.set(testString, forKey: testKey) XCTAssertTrue(stringSaved, "String did not save to Keychain") // delete all - let removeSuccessful = KeychainWrapper.defaultKeychainWrapper.removeAllKeys() + let removeSuccessful = KeychainWrapper.standard.removeAllKeys() XCTAssertTrue(removeSuccessful, "Failed to remove all Keys") // confirm our test value was deleted - let retrievedValue = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) + let retrievedValue = KeychainWrapper.standard.string(forKey: testKey) XCTAssertNil(retrievedValue, "Test value was not deleted") } func testWipeKeychainDeletesSpecificKey() { // save a value we can test delete on - let stringSaved = KeychainWrapper.defaultKeychainWrapper.set(testString, forKey: testKey) + let stringSaved = KeychainWrapper.standard.set(testString, forKey: testKey) XCTAssertTrue(stringSaved, "String did not save to Keychain") @@ -50,12 +50,12 @@ class KeychainWrapperDeleteTests: XCTestCase { KeychainWrapper.wipeKeychain() // confirm our test value was deleted - let retrievedValue = KeychainWrapper.defaultKeychainWrapper.string(forKey: testKey) + let retrievedValue = KeychainWrapper.standard.string(forKey: testKey) XCTAssertNil(retrievedValue, "Test value was not deleted") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testRemoveAllKeysOnlyRemovesKeysForCurrentServiceName() { diff --git a/SwiftKeychainWrapperTests/KeychainWrapperPrimitiveValueTests.swift b/SwiftKeychainWrapperTests/KeychainWrapperPrimitiveValueTests.swift index 87544fa..6ee11cc 100644 --- a/SwiftKeychainWrapperTests/KeychainWrapperPrimitiveValueTests.swift +++ b/SwiftKeychainWrapperTests/KeychainWrapperPrimitiveValueTests.swift @@ -27,18 +27,18 @@ class KeychainWrapperPrimitiveValueTests: XCTestCase { } func testIntegerSave() { - let valueSaved = KeychainWrapper.defaultKeychainWrapper.set(testInteger, forKey: testKey) + let valueSaved = KeychainWrapper.standard.set(testInteger, forKey: testKey) XCTAssertTrue(valueSaved, "Integer value did not save to Keychain") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testIntegerRetrieval() { - KeychainWrapper.defaultKeychainWrapper.set(testInteger, forKey: testKey) + KeychainWrapper.standard.set(testInteger, forKey: testKey) - if let retrievedValue = KeychainWrapper.defaultKeychainWrapper.integer(forKey: testKey) { + if let retrievedValue = KeychainWrapper.standard.integer(forKey: testKey) { XCTAssertEqual(retrievedValue, testInteger, "Integer value retrieved for key should equal value saved for key") } else { XCTFail("Integer value for Key not found") @@ -46,18 +46,18 @@ class KeychainWrapperPrimitiveValueTests: XCTestCase { } func testBoolSave() { - let valueSaved = KeychainWrapper.defaultKeychainWrapper.set(testBool, forKey: testKey) + let valueSaved = KeychainWrapper.standard.set(testBool, forKey: testKey) XCTAssertTrue(valueSaved, "Bool value did not save to Keychain") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testBoolRetrieval() { - KeychainWrapper.defaultKeychainWrapper.set(testBool, forKey: testKey) + KeychainWrapper.standard.set(testBool, forKey: testKey) - if let retrievedValue = KeychainWrapper.defaultKeychainWrapper.bool(forKey: testKey) { + if let retrievedValue = KeychainWrapper.standard.bool(forKey: testKey) { XCTAssertEqual(retrievedValue, testBool, "Bool value retrieved for key should equal value saved for key") } else { XCTFail("Bool value for Key not found") @@ -65,18 +65,18 @@ class KeychainWrapperPrimitiveValueTests: XCTestCase { } func testFloatSave() { - let valueSaved = KeychainWrapper.defaultKeychainWrapper.set(testFloat, forKey: testKey) + let valueSaved = KeychainWrapper.standard.set(testFloat, forKey: testKey) XCTAssertTrue(valueSaved, "Float value did not save to Keychain") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testFloatRetrieval() { - KeychainWrapper.defaultKeychainWrapper.set(testFloat, forKey: testKey) + KeychainWrapper.standard.set(testFloat, forKey: testKey) - if let retrievedValue = KeychainWrapper.defaultKeychainWrapper.float(forKey: testKey) { + if let retrievedValue = KeychainWrapper.standard.float(forKey: testKey) { XCTAssertEqual(retrievedValue, testFloat, "Float value retrieved for key should equal value saved for key") } else { XCTFail("Float value for Key not found") @@ -84,18 +84,18 @@ class KeychainWrapperPrimitiveValueTests: XCTestCase { } func testDoubleSave() { - let valueSaved = KeychainWrapper.defaultKeychainWrapper.set(testDouble, forKey: testKey) + let valueSaved = KeychainWrapper.standard.set(testDouble, forKey: testKey) XCTAssertTrue(valueSaved, "Double value did not save to Keychain") // clean up keychain - KeychainWrapper.defaultKeychainWrapper.remove(key: testKey) + KeychainWrapper.standard.removeObject(forKey: testKey) } func testDoubleRetrieval() { - KeychainWrapper.defaultKeychainWrapper.set(testDouble, forKey: testKey) + KeychainWrapper.standard.set(testDouble, forKey: testKey) - if let retrievedValue = KeychainWrapper.defaultKeychainWrapper.double(forKey: testKey) { + if let retrievedValue = KeychainWrapper.standard.double(forKey: testKey) { XCTAssertEqual(retrievedValue, testDouble, "Double value retrieved for key should equal value saved for key") } else { XCTFail("Double value for Key not found") diff --git a/SwiftKeychainWrapperTests/KeychainWrapperTests.swift b/SwiftKeychainWrapperTests/KeychainWrapperTests.swift index e7b0bcb..52d4e03 100644 --- a/SwiftKeychainWrapperTests/KeychainWrapperTests.swift +++ b/SwiftKeychainWrapperTests/KeychainWrapperTests.swift @@ -26,8 +26,8 @@ class KeychainWrapperTests: XCTestCase { let uniqueAccessGroup = UUID().uuidString let customKeychainWrapperInstance = KeychainWrapper(serviceName: uniqueServiceName, accessGroup: uniqueAccessGroup) - XCTAssertNotEqual(customKeychainWrapperInstance.serviceName, KeychainWrapper.defaultKeychainWrapper.serviceName, "Custom instance initialized with unique service name, should not match defaultKeychainWrapper Service Name") - XCTAssertNotEqual(customKeychainWrapperInstance.accessGroup, KeychainWrapper.defaultKeychainWrapper.accessGroup, "Custom instance initialized with unique access group, should not match defaultKeychainWrapper Access Group") + XCTAssertNotEqual(customKeychainWrapperInstance.serviceName, KeychainWrapper.standard.serviceName, "Custom instance initialized with unique service name, should not match standard Service Name") + XCTAssertNotEqual(customKeychainWrapperInstance.accessGroup, KeychainWrapper.standard.accessGroup, "Custom instance initialized with unique access group, should not match standard Access Group") } func testAccessibility() { @@ -44,14 +44,14 @@ class KeychainWrapperTests: XCTestCase { let key = "testKey" for accessibilityOption in accessibilityOptions { - KeychainWrapper.defaultKeychainWrapper.set("Test123", forKey: key, withAccessibility: accessibilityOption) + KeychainWrapper.standard.set("Test123", forKey: key, withAccessibility: accessibilityOption) - let accessibilityForKey = KeychainWrapper.defaultKeychainWrapper.accessibilityOfKey(key) + let accessibilityForKey = KeychainWrapper.standard.accessibilityOfKey(key) XCTAssertEqual(accessibilityForKey, accessibilityOption, "Accessibility does not match. Expected: \(accessibilityOption) Found: \(accessibilityForKey)") // INFO: If re-using a key but with a different accessibility, first remove the previous key value using removeObjectForKey(:withAccessibility) using the same accessibilty it was saved with - KeychainWrapper.defaultKeychainWrapper.remove(key: key, withAccessibility: accessibilityOption) + KeychainWrapper.standard.removeObject(forKey: key, withAccessibility: accessibilityOption) } } }