Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jrendel-dil committed Sep 16, 2016
2 parents 8e81e0f + f05a327 commit f369c9b
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 565 deletions.
17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -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().setString("Some String", forKey: "myKey")
let saveSuccessful: Bool = KeychainWrapper.defaultKeychainWrapper.set("Some String", forKey: "myKey")
```

Retrieve a string value from keychain:
```
let retrievedString: String? = KeychainWrapper.defaultKeychainWrapper().stringForKey("myKey")
let retrievedString: String? = KeychainWrapper.defaultKeychainWrapper.string(forKey: "myKey")
```

Remove a string value from keychain:
```
let removeSuccessful: Bool = KeychainWrapper.defaultKeychainWrapper().removeObjectForKey("myKey")
let removeSuccessful: Bool = KeychainWrapper.defaultKeychainWrapper.remove(key: "myKey")
```

##Custom Instance
Expand All @@ -43,19 +43,19 @@ let customKeychainWrapperInstance = KeychainWrapper(serviceName: uniqueServiceNa
The custom instance can then be used in place of the shared instance or static accessors:

```
let saveSuccessful: Bool = customKeychainWrapperInstance.setString("Some String", forKey: "myKey")
let saveSuccessful: Bool = customKeychainWrapperInstance.set("Some String", forKey: "myKey")
let retrievedString: String? = customKeychainWrapperInstance.stringForKey("myKey")
let retrievedString: String? = customKeychainWrapperInstance.string(forKey: "myKey")
let removeSuccessful: Bool = customKeychainWrapperInstance.removeObjectForKey("myKey")
let removeSuccessful: Bool = customKeychainWrapperInstance.remove(key: "myKey")
```

##Accessibility Options

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().setString("Some String", forKey: "myKey", withAccessibility: .AfterFirstUnlock)
KeychainWrapper.defaultKeychainWrapper.set("Some String", forKey: "myKey", withAccessibility: .AfterFirstUnlock)
```

##Installation
Expand Down Expand Up @@ -84,6 +84,9 @@ Download and drop ```KeychainWrapper.swift``` and ```KeychainItemAcessibility.sw

## Release History

* 2.2
* Updated to support Swift 3.0
* Remove deprecated functions (static access)
* 2.1
* Updated to support Swift 2.3
* 2.0
Expand Down
2 changes: 1 addition & 1 deletion SwiftKeychainWrapper.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftKeychainWrapper'
s.version = '2.1.0'
s.version = '2.2.0'
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.'
Expand Down
56 changes: 45 additions & 11 deletions SwiftKeychainWrapper.xcodeproj/project.pbxproj
Expand Up @@ -16,7 +16,6 @@
9694C2B51A66097F005B3030 /* SwiftKeychainWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 9694C2B41A66097F005B3030 /* SwiftKeychainWrapper.h */; settings = {ATTRIBUTES = (Public, ); }; };
9694C2BB1A66097F005B3030 /* SwiftKeychainWrapper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9694C2B01A66097F005B3030 /* SwiftKeychainWrapper.framework */; };
9694C2CD1A660F90005B3030 /* KeychainWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9694C2CC1A660F90005B3030 /* KeychainWrapper.swift */; };
9694C2D01A660F9C005B3030 /* KeychainWrapperDeprecatedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9694C2CE1A660F9C005B3030 /* KeychainWrapperDeprecatedTests.swift */; };
9694C2D11A660F9C005B3030 /* TestObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9694C2CF1A660F9C005B3030 /* TestObject.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -44,7 +43,6 @@
9694C2BA1A66097F005B3030 /* SwiftKeychainWrapperTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftKeychainWrapperTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9694C2C01A66097F005B3030 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9694C2CC1A660F90005B3030 /* KeychainWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainWrapper.swift; sourceTree = "<group>"; };
9694C2CE1A660F9C005B3030 /* KeychainWrapperDeprecatedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeychainWrapperDeprecatedTests.swift; sourceTree = "<group>"; };
9694C2CF1A660F9C005B3030 /* TestObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObject.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -112,7 +110,6 @@
9694C2CF1A660F9C005B3030 /* TestObject.swift */,
470A7D3A1CCE40EE001768EE /* KeychainWrapperTests.swift */,
9661773F1D597872000772C5 /* KeychainWrapperDefaultWrapperTests.swift */,
9694C2CE1A660F9C005B3030 /* KeychainWrapperDeprecatedTests.swift */,
96405CF31CA57F460080FF45 /* KeychainWrapperDeleteTests.swift */,
477728B81CAF29E500905FE4 /* KeychainWrapperPrimitiveValueTests.swift */,
9694C2BF1A66097F005B3030 /* Supporting Files */,
Expand Down Expand Up @@ -186,7 +183,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Jason Rendel";
TargetAttributes = {
9694C2AF1A66097F005B3030 = {
Expand All @@ -195,6 +192,7 @@
};
9694C2B91A66097F005B3030 = {
CreatedOnToolsVersion = 6.1.1;
DevelopmentTeam = QDW4H7J3NE;
LastSwiftMigration = 0800;
};
};
Expand Down Expand Up @@ -253,7 +251,6 @@
96405CF41CA57F460080FF45 /* KeychainWrapperDeleteTests.swift in Sources */,
477728B91CAF29E500905FE4 /* KeychainWrapperPrimitiveValueTests.swift in Sources */,
966177401D597872000772C5 /* KeychainWrapperDefaultWrapperTests.swift in Sources */,
9694C2D01A660F9C005B3030 /* KeychainWrapperDeprecatedTests.swift in Sources */,
470A7D3B1CCE40EE001768EE /* KeychainWrapperTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -273,7 +270,24 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -284,7 +298,25 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand All @@ -307,7 +339,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -338,7 +370,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -364,7 +396,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
Expand All @@ -389,7 +421,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -416,6 +448,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = QDW4H7J3NE;
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
Expand All @@ -442,7 +475,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.jasonrendel.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -465,6 +498,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = YES;
DEVELOPMENT_TEAM = QDW4H7J3NE;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -485,7 +519,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.jasonrendel.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions SwiftKeychainWrapper/Info.plist
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.1.0</string>
<string>2.2.0</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
38 changes: 17 additions & 21 deletions SwiftKeychainWrapper/KeychainItemAccessibility.swift
Expand Up @@ -39,39 +39,39 @@ public enum KeychainItemAccessibility {
After the first unlock, the data remains accessible until the next restart. This is recommended for items that need to be accessed by background applications. Items with this attribute migrate to a new device when using encrypted backups.
*/
@available(iOS 4, *)
case AfterFirstUnlock
case afterFirstUnlock

/**
The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user.
After the first unlock, the data remains accessible until the next restart. This is recommended for items that need to be accessed by background applications. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
*/
@available(iOS 4, *)
case AfterFirstUnlockThisDeviceOnly
case afterFirstUnlockThisDeviceOnly

/**
The data in the keychain item can always be accessed regardless of whether the device is locked.
This is not recommended for application use. Items with this attribute migrate to a new device when using encrypted backups.
*/
@available(iOS 4, *)
case Always
case always

/**
The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device.
This is recommended for items that only need to be accessible while the application is in the foreground. Items with this attribute never migrate to a new device. After a backup is restored to a new device, these items are missing. No items can be stored in this class on devices without a passcode. Disabling the device passcode causes all items in this class to be deleted.
*/
@available(iOS 8, *)
case WhenPasscodeSetThisDeviceOnly
case whenPasscodeSetThisDeviceOnly

/**
The data in the keychain item can always be accessed regardless of whether the device is locked.
This is not recommended for application use. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
*/
@available(iOS 4, *)
case AlwaysThisDeviceOnly
case alwaysThisDeviceOnly

/**
The data in the keychain item can be accessed only while the device is unlocked by the user.
Expand All @@ -81,17 +81,17 @@ public enum KeychainItemAccessibility {
This is the default value for keychain items added without explicitly setting an accessibility constant.
*/
@available(iOS 4, *)
case WhenUnlocked
case whenUnlocked

/**
The data in the keychain item can be accessed only while the device is unlocked by the user.
This is recommended for items that need to be accessible only while the application is in the foreground. Items with this attribute do not migrate to a new device. Thus, after restoring from a backup of a different device, these items will not be present.
*/
@available(iOS 4, *)
case WhenUnlockedThisDeviceOnly
case whenUnlockedThisDeviceOnly

static func accessibilityForAttributeValue(keychainAttrValue: CFString) -> KeychainItemAccessibility? {
static func accessibilityForAttributeValue(_ keychainAttrValue: CFString) -> KeychainItemAccessibility? {
for (key, value) in keychainItemAccessibilityLookup {
if value == keychainAttrValue {
return key
Expand All @@ -104,24 +104,20 @@ public enum KeychainItemAccessibility {

private let keychainItemAccessibilityLookup: [KeychainItemAccessibility:CFString] = {
var lookup: [KeychainItemAccessibility:CFString] = [
.AfterFirstUnlock: kSecAttrAccessibleAfterFirstUnlock,
.AfterFirstUnlockThisDeviceOnly: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
.Always: kSecAttrAccessibleAlways,
.AlwaysThisDeviceOnly : kSecAttrAccessibleAlwaysThisDeviceOnly,
.WhenUnlocked: kSecAttrAccessibleWhenUnlocked,
.WhenUnlockedThisDeviceOnly: kSecAttrAccessibleWhenUnlockedThisDeviceOnly
.afterFirstUnlock: kSecAttrAccessibleAfterFirstUnlock,
.afterFirstUnlockThisDeviceOnly: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
.always: kSecAttrAccessibleAlways,
.whenPasscodeSetThisDeviceOnly: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
.alwaysThisDeviceOnly : kSecAttrAccessibleAlwaysThisDeviceOnly,
.whenUnlocked: kSecAttrAccessibleWhenUnlocked,
.whenUnlockedThisDeviceOnly: kSecAttrAccessibleWhenUnlockedThisDeviceOnly
]

// INFO: While this framework only supports iOS 8 and up, the files themselves can be pulled directly into an iOS 7 project and work fine as long as this #available check is in place. Unfortunately, this also generates a warning in the framework project for now.
if #available(iOSApplicationExtension 8, *) {
lookup[.WhenPasscodeSetThisDeviceOnly] = kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
}


return lookup
}()

extension KeychainItemAccessibility : KeychainAttrRepresentable {
internal var keychainAttrValue: CFString {
return keychainItemAccessibilityLookup[self]!
}
}
}

0 comments on commit f369c9b

Please sign in to comment.