Skip to content
KeyClip is yet another Keychain library written in Swift.
Swift Ruby Makefile Shell
Branch: master
Clone or download
s-aska Merge pull request #22 from graphiclife/master
Swift Errors & API change
Latest commit 20d18e5 May 6, 2019


Build Status Carthage compatible

KeyClip is yet another Keychain library written in Swift.



String"access_token", string: "********") // -> Bool

let token = KeyClip.load("access_token") as String?

KeyClip.delete("access_token") // Remove the data

KeyClip.clear() // Remove all the data

KeyClip.exists("access_token") // -> Bool


Must be compatible to NSJSONSerialization.

Valid JSON elements are Dictionary, Array, String, Number, Boolean and null."account", dictionary: ["name": "aska", "token": "******"]) // -> Bool

let dictionary = KeyClip.load("account") as NSDictionary?

NSData"data", data: NSData()) // -> Bool

let data = KeyClip.load("data") as NSData?

Your Class"account", dictionary: account.dictionaryValue)

let account = KeyClip.load("account") { (dictionary) -> Account in
    return Account(dictionary)

class Account {
    let name: String
    let password: String

    init(_ dictionary: NSDictionary) { = dictionary["name"] as String
        self.password = dictionary["password"] as String

    var dictionaryValue: [String: String] {
        return ["name": name, "password": password]

Error Handling

Return value

let success ="password", string: "********")
if !success {
    // Show Alert "Saving password to keychain failed"

Clojure"password", string: "********") { error in
    let status = error.code // OSStatus
    // Show Alert "Saving failed \(error.localizedDescription)(\(error.code))"

Debug print



let clip = KeyClip.Builder()

    // kSecAttrService
    .service(NSBundle.mainBundle().bundleIdentifier) // default

    // kSecAttrAccessible
    .accessible(kSecAttrAccessibleAfterFirstUnlock) // default

    // kSecAttrAccessGroup
    .accessGroup("") // default is nil


Note to accessGroup

⚠️ iOS Simulator's keychain implementation does not support kSecAttrAccessGroup. (always "test")

⚠️ kSecAttrAccessGroup must match the App Identifier prefix.

How to check the App Identifier

Entitlement.plist's keychain-access-groups or App Identifier.

KeyClip.defaultAccessGroup() // -> String (eg. XXXX23F3DC53.*)


  • iOS 8.0+ / Mac OS X 10.10+
  • Xcode 8



Add the following line to your Cartfile

github "s-aska/KeyClip"


Add the following line to your Podfile

pod 'KeyClip'


KeyClip is released under the MIT license. See LICENSE for details.

You can’t perform that action at this time.