Skip to content

Using KeychainSwift in Objective C project

Evgenii Neumerzhitckii edited this page Jan 21, 2017 · 4 revisions

This is how to use KeychainSwift in Objective-C apps.

  1. Add KeychainSwiftCBridge.swift to your project and extend it to suit your needs.
  2. Import swift code in your Objective-C file: #import "YOUR_PRODUCT_MODULE_NAME-Swift.h"
  3. Use KeychainSwift in your ObjC code:
- (void)viewDidLoad {
    [super viewDidLoad];
 
    KeychainSwiftCBridge *keychain = [[KeychainSwiftCBridge alloc] init];
    [keychain set:@"Hello World" forKey:@"my key"];
    NSString *value = [keychain get:@"my key"];
}

Note: You might need to remove import KeychainSwift from KeychainSwiftCBridge.swift file in your project.

Clone this wiki locally