처음에 라이브러리를 받아온다.
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 삭제
}
}
}
}
'iOS' 카테고리의 다른 글
Swift - NumberFormatter (0) | 2024.05.14 |
---|---|
Swift - 연산 프로퍼티(Computed Property) get ,set (0) | 2024.05.04 |
Swift - 싱글톤 패턴 적용 (0) | 2024.05.04 |
Swift - Propery Observer (didSet) (0) | 2024.05.03 |
Swift - hugging priority / compression resistance priority (0) | 2024.04.21 |
댓글