Convenient, beautiful and easy to use KeychainAccess, that written in Swift
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
- Create
Podfile
into your Xcode project. Open upTerminal
→cd
into your project's top-level directory → Run the following command:
$ pod init
- Open up created
Podfile
.
$ open Podfile
- In the
Podfile
that appears, specify. Instead of<Your Target Name>
, enter your project's name :
platform :ios, ‘8.0’
target '<Your Target Name>' do
use_frameworks!
pod 'YFKeychainAccess'
end
- Then, run the following command:
$ pod update
$ pod install
- Finally, open your Xcode
<Your Target Name>.xcworkspace
.
import YFKeychainAccess
let keychain = YFKeychainAccess() // You can add 'keyPrefix' and 'options' to customize KeychainAccess
do {
try keychain.set(value, forKey: "KEY") // You can add 'accessible' parameter too
// 'set' function update item or creates a new one
} catch {
// Handle error if necessary
}
let keychain = YFKeychainAccess() // You can add 'keyPrefix' and 'options' to customize KeychainAccess
do {
let data = try keychain.data(forKey: "DATA_KEY")
let string = try keychain.string(forKey: "STRING_KEY")
let bool = try keychain.bool(forKey: "BOOL_KEY")
let int = try keychain.(forKey: "INT_KEY")
let float = try keychain.float(forKey: "FLOAT_KEY")
let double = try keychain.double(forKey: "DOUBLE_KEY")
} catch {
// Handle error if necessary
}
let keychain = YFKeychainAccess() // You can add 'keyPrefix' and 'options' to customize KeychainAccess
do {
try keychin.delete(forKey: "KEY") // Delete one item for key
try keychin.deleteAll() // Delete all item for this app
} catch {
// Handle error if necessary
}
let keychain = YFKeychainAccess() // You can add 'keyPrefix' and 'options' to customize KeychainAccess
do {
try keychin.contains(forKey: "KEY")
} catch {
// Handle error if necessary
}
Released under the MIT license. See LICENSE for details.