본문 바로가기
iOS

Swift - KeychainWrapper

by minsol Kim 2024. 5. 4.

처음에 라이브러리를 받아온다. 

 

https://github.com/jrendel/SwiftKeychainWrapper

 

GitHub - jrendel/SwiftKeychainWrapper: A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift. - jrendel/SwiftKeychainWrapper

github.com

 

Keychain 저장, 반환, 삭제

class SignDataManager {
    static let shared = SignDataManager()
    
    private init() {}
    
    var birthDate: String? {
        get {
            return KeychainWrapper.standard.string(forKey: "birthDate") // keychain 반환
        }
        set {
            if let newValue = newValue {
                KeychainWrapper.standard.set(newValue, forKey: "birthDate") //keychain 저장
            } else {
                KeychainWrapper.standard.removeObject(forKey: "birthDate") //keychain 삭제
            }
        }
    }
}

 

댓글