What is SAMKeychain?
SAMKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keychain on Mac OS X and iOS. It provides a clean, easy-to-use Objective-C interface that abstracts away the complexity of Apple’s C-based Keychain Services API. Originally inspired by EMKeychain and SDKeychain, SAMKeychain has evolved into a robust solution that handles the intricate details of keychain management, allowing you to focus on your application logic rather than wrestling with low-level C APIs.Key Features
Simple API
Clean class methods for common keychain operations - no complex C structures or error codes to manage
Cross-Platform
Works on macOS 10.8+, iOS 5.0+, tvOS 9.0+, and watchOS 2.0+
Modern Objective-C
Built with ARC support and includes nullability annotations for better Swift interoperability
Flexible Integration
Install via CocoaPods, Carthage, or manually - whatever fits your workflow
When to Use SAMKeychain
Use SAMKeychain when you need to:- Store user credentials securely - Passwords, tokens, and authentication data
- Persist sensitive data - API keys, encryption keys, or other secrets
- Share data between apps - Using keychain access groups (iOS)
- Sync data via iCloud - With keychain synchronization support
While SAMKeychain simplifies keychain access, it doesn’t make the keychain itself more stable. You should always check for errors and handle failures appropriately in your code.
Core Concepts
Service and Account
The keychain organizes data using two primary identifiers:- Service - Typically your app’s bundle identifier or a specific service name (e.g.,
com.yourcompany.yourapp) - Account - The username or account identifier (e.g.,
user@example.com)
Two Usage Patterns
SAMKeychain offers two ways to interact with the keychain:-
Class Methods - Quick, one-line operations for common tasks:
-
SAMKeychainQuery - Advanced interface with more control over attributes:
Platform Support
| Platform | Minimum Version |
|---|---|
| macOS | 10.8 |
| iOS | 5.0 |
| tvOS | 9.0 |
| watchOS | 2.0 |
Security Considerations
The default accessibility setting is highly insecure. See Apple’s Keychain Item Accessibility Constants documentation for all available options.Next Steps
Installation
Get SAMKeychain integrated into your project
Quick Start
Write your first keychain operation in minutes
