Skip to main content
SAMKeychain can be integrated into your project using several different methods. Choose the one that best fits your workflow.
SAMKeychain requires ARC (Automatic Reference Counting) to be enabled in your project.

Installation Methods

pod 'SAMKeychain'

CocoaPods

1

Add to Podfile

Add the following line to your Podfile:
pod 'SAMKeychain'
If you need a specific version:
pod 'SAMKeychain', '~> 1.5.3'
2

Install dependencies

Run the pod install command:
pod install
3

Import the header

Import SAMKeychain in your code:
#import <SAMKeychain/SAMKeychain.h>

Carthage

1

Add to Cartfile

Add the following line to your Cartfile:
github "soffes/SAMKeychain"
For a specific version:
github "soffes/SAMKeychain" ~> 1.5.3
2

Build the framework

Run Carthage to build the framework:
carthage update
3

Add framework to project

Drag the built SAMKeychain.framework from Carthage/Build to your project’s “Linked Frameworks and Libraries” section in Xcode.
4

Add run script

Add a new Run Script Phase in your target’s Build Phases:
/usr/local/bin/carthage copy-frameworks
Add the framework path to “Input Files”:
$(SRCROOT)/Carthage/Build/iOS/SAMKeychain.framework
5

Import the header

Import SAMKeychain in your code:
#import <SAMKeychain/SAMKeychain.h>

Manual Installation

If you prefer not to use a dependency manager, you can manually add SAMKeychain to your project.
1

Download source files

Download or clone the SAMKeychain repository from GitHub.
2

Add files to project

Add the following files from the Sources directory to your Xcode project:
  • SAMKeychain.h
  • SAMKeychain.m
  • SAMKeychainQuery.h
  • SAMKeychainQuery.m
Make sure “Copy items if needed” is checked when adding the files to your project.
3

Add Security framework

Add the Security.framework to your target:
  1. Select your project in the Project Navigator
  2. Select your target
  3. Go to the “General” tab
  4. Scroll to “Frameworks, Libraries, and Embedded Content”
  5. Click the ”+” button
  6. Search for and add Security.framework
4

Import the header

Import SAMKeychain in your code:
#import "SAMKeychain.h"
Note the use of quotes instead of angle brackets when using manual installation.

Verification

To verify that SAMKeychain is correctly installed, try building your project. You should be able to import and use SAMKeychain without any errors:
#import <SAMKeychain/SAMKeychain.h>

// Test that SAMKeychain is available
NSArray *accounts = [SAMKeychain allAccounts];
NSLog(@"SAMKeychain is working! Found %lu accounts", (unsigned long)accounts.count);

Platform-Specific Notes

macOS

No additional configuration is required for macOS. The Security framework is available on macOS 10.8 and later.

iOS, tvOS, and watchOS

For iOS, tvOS, and watchOS, you can configure keychain accessibility and access groups:
// Set accessibility type (iOS 4.0+)
[SAMKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlocked];

Access Groups (iOS)

If you need to share keychain data between apps, configure access groups in your entitlements file and use SAMKeychainQuery:
SAMKeychainQuery *query = [[SAMKeychainQuery alloc] init];
query.service = @"MyService";
query.account = @"user@example.com";
query.accessGroup = @"com.yourcompany.shared";

Troubleshooting

Make sure the Security framework is added to your target. See the manual installation steps above.
You may have included SAMKeychain through multiple methods (e.g., both CocoaPods and manual installation). Choose one installation method and remove the other.

Next Steps

Quick Start Guide

Now that SAMKeychain is installed, learn how to use it with our quick start guide.