{"id":25646207,"url":"https://github.com/yankodimitrov/swiftkeychain","last_synced_at":"2025-04-15T13:40:49.231Z","repository":{"id":23292743,"uuid":"26651852","full_name":"yankodimitrov/SwiftKeychain","owner":"yankodimitrov","description":"An elegant Swift wrapper around the Apple Keychain API","archived":false,"fork":false,"pushed_at":"2023-05-23T21:38:39.000Z","size":229,"stargazers_count":96,"open_issues_count":7,"forks_count":24,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T09:03:53.548Z","etag":null,"topics":["keychain","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yankodimitrov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-14T18:31:12.000Z","updated_at":"2024-11-24T11:23:13.000Z","dependencies_parsed_at":"2024-06-19T00:46:23.117Z","dependency_job_id":"284af732-acfe-4799-aec2-b016403812dd","html_url":"https://github.com/yankodimitrov/SwiftKeychain","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yankodimitrov%2FSwiftKeychain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yankodimitrov%2FSwiftKeychain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yankodimitrov%2FSwiftKeychain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yankodimitrov%2FSwiftKeychain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yankodimitrov","download_url":"https://codeload.github.com/yankodimitrov/SwiftKeychain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249081517,"owners_count":21209712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keychain","swift"],"created_at":"2025-02-23T10:19:17.626Z","updated_at":"2025-04-15T13:40:49.209Z","avatar_url":"https://github.com/yankodimitrov.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"#SwiftKeychain\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n## Abstract\nSwift wrapper for working with the Keychain API implemented with Protocol Oriented Programming.\n\nYou create an implementation of the \u003ccode\u003eKeychainGenericPasswordType\u003c/code\u003e protocol that encapsulates the data that you want to store in the \u003ccode\u003eKeychain\u003c/code\u003e. Most of the implementation is done for you by using default protocol implementations, such as setting the default service name and access mode (\u003ccode\u003ekSecAttrAccessibleWhenUnlocked\u003c/code\u003e).\n\nThen you call the \u003ccode\u003eKeychainItemType\u003c/code\u003e methods to save, remove or fetch the item from the provided as argument \u003ccode\u003eKeychainServiceType\u003c/code\u003e protocol implementation.\n\n![SwiftKeychain Protocols](https://raw.githubusercontent.com/yankodimitrov/SwiftKeychain/Keychain-1.0/Resources/Protocols.png)\n\nLet's say we want to store the access token and username for an Instagram account in the Keychain:\n\n```swift\nstruct InstagramAccount: KeychainGenericPasswordType {\n    \n    let accountName: String\n    let token: String\n    var data = [String: AnyObject]()\n    \n    var dataToStore: [String: AnyObject] {\n        return [\"token\": token]\n    }\n    \n    var accessToken: String? {\n        return data[\"token\"] as? String\n    }\n    \n    init(name: String, accessToken: String = \"\") {\n        accountName = name\n        token = accessToken\n    }\n}\n```\nIn \u003ccode\u003evar dataToStore: [String: AnyObject]\u003c/code\u003e you return the Dictionary that you want to be saved in the Keychain and when you fetch the item from the Keychain its data will be populated in your \u003ccode\u003evar data: [String: AnyObject]\u003c/code\u003e property.\n\n### Save Item\n```swift\nlet newAccount = InstagramAccount(name: \"John\", accessToken: \"123456\")\n\ndo {\n    \n    try newAccount.saveInKeychain()\n\n} catch {\n    \n    print(error)\n}\n```\n*Note:* The provided implementation of the \u003ccode\u003eKeychainServiceType\u003c/code\u003e protocol will replace the item if it already exists in the Keychain database.\n\n### Remove Item\n```swift\nlet account = InstagramAccount(name: \"John\")\n\ndo {\n    \n    try account.removeFromKeychain()\n\n} catch {\n    \n    print(error)\n}\n```\n\n### Fetch Item\n```swift\nvar account = InstagramAccount(name: \"John\")\n\ndo {\n    \n    try account.fetchFromKeychain()\n    \n    if let token = account.accessToken {\n\n        print(\"name: \\(account.accountName), token: \\(token)\")\n    }\n\n} catch {\n\n    print(error)\n}\n```\n\n## Installation\nSwiftKeychain requires Swift 2.0 and Xcode 7 and supports iOS, OSX, watchOS and tvOS.\n\n#### Manually\nCopy the \u003ccode\u003eKeychain/Keychain.swift\u003c/code\u003e file to your project.\n\n#### Carthage\nAdd the following line to your [Cartfile](https://github.com/carthage/carthage)\n```swift\ngithub \"yankodimitrov/SwiftKeychain\" \"master\"\n```\n\n#### CocoaPods\nAdd the following line to your [Podfile](https://guides.cocoapods.org/)\n```swift\npod “SwiftKeychain”\n```\n\n## License\nSwiftKeychain is released under the MIT license. See the LICENSE.txt file for more info.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyankodimitrov%2Fswiftkeychain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyankodimitrov%2Fswiftkeychain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyankodimitrov%2Fswiftkeychain/lists"}