Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- SeSAC
- KeyPath
- arc
- Subject
- Firebase
- Swift Tuist
- realm
- 카카오뱅크 ios
- ribs
- swift database
- RxSwift
- xcode
- GCD
- Combine
- JSON
- swift 5.9
- swift 6
- Subscribe
- SwiftUI
- swift db
- observable
- Firebase Analytics
- ios swiftdata
- Tuist
- 네트워크 통신
- ios
- Tuist Swift
- swift
- ios database
- swiftdata
Archives
- Today
- Total
천원의 개발
iOS UserDefaults 사용법 본문
우리가 앱 개발을 하다보면 데이터베이스를 사용하지 않고 앱 내부에서 사용자의 정보를 저장해야 하는 순간이 올 것이다. 이럴때 사용 하는 것 이 UserDefaults다.
https://developer.apple.com/documentation/foundation/userdefaults
Apple Developer Documentation
developer.apple.com
UserDefaults는 App 시작시 사용자의 기본 데이터베이스를 키-값 쌍으로 지속적으로 저장하는 인터페이스이다.
1. set으로 저장하기
UserDefaults.standard.set(25, forKey: "age") // Int 형태로 저장
UserDefaults.standard.set("Jack", forKey: "name") // String 형태로 저장
set 함수를 통해 저장 할 수 있습니다.
2. 가져오기
UserDefaults.standard.integer(forKey: "age") // print하면 25가 출력
UserDefaults.standard.string(forKey: "name") // print하면 "Jack" 출력
자료형을 통해 key값으로 원하는 value를 가져올 수 있습니다.
3. 삭제하기
UserDefaults.standard.removeObject(forKey: "age")
'iOS&Swift🍎 > iOS' 카테고리의 다른 글
iOS HTTP 통신 허용 (0) | 2022.08.13 |
---|---|
iOS 커스텀 폰트 사용법 (0) | 2022.08.11 |
iOS Local Notification 사용법 (0) | 2022.07.29 |
iOS Alert 사용법 (0) | 2022.07.15 |
iOS DateFormatter 사용법 (0) | 2022.07.14 |