# UserDefaults & Keychain (iOS) > UserDefaults, Keychain Services, การจัดเก็บข้อมูลที่ปลอดภัย, ข้อมูลที่ละเอียดอ่อน, แนวทางปฏิบัติที่ดีที่สุด - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: iOS](https://sharpskill.dev/th/technologies/ios/interview-questions.md) ## 1. UserDefaults ใน iOS คืออะไร? **คำตอบ** UserDefaults คือระบบจัดเก็บข้อมูลที่เรียบง่ายสำหรับการเก็บข้อมูลที่ไม่ละเอียดอ่อนอย่างถาวร เช่น การตั้งค่าของผู้ใช้ ข้อมูลจะถูกจัดเก็บในรูปแบบ plist บนดิสก์และเข้าถึงได้ง่าย อย่างไรก็ตาม ข้อมูลไม่ได้ถูกเข้ารหัส ดังนั้นจึงไม่ควรจัดเก็บข้อมูลที่ละเอียดอ่อน เช่น รหัสผ่านหรือโทเค็นการยืนยันตัวตนไว้ที่นั่น ## 2. Keychain Services ใน iOS คืออะไร? **คำตอบ** Keychain Services คือ API ด้านความปลอดภัยที่ช่วยให้สามารถจัดเก็บข้อมูลที่ละเอียดอ่อนในรูปแบบที่เข้ารหัสและปลอดภัย โดยใช้ Secure Enclave บนอุปกรณ์รุ่นใหม่เพื่อปกป้องข้อมูล Keychain เป็นแนวทางที่แนะนำสำหรับการจัดเก็บรหัสผ่าน โทเค็น ใบรับรอง และข้อมูลสำคัญด้านความปลอดภัยอื่น ๆ ของแอปพลิเคชัน ## 3. จะเข้าถึงอินสแตนซ์มาตรฐานของ UserDefaults ได้อย่างไร? **คำตอบ** UserDefaults.standard เป็นวิธีมาตรฐานในการเข้าถึงอินสแตนซ์ที่ใช้ร่วมกันแบบเริ่มต้นทั่วทั้งแอปพลิเคชัน อินสแตนซ์นี้จะเก็บข้อมูลลงดิสก์โดยอัตโนมัติ สามารถสร้างอินสแตนซ์แบบมีชื่อด้วย init(suiteName:) เพื่อแชร์ข้อมูลระหว่างแอปและส่วนขยายผ่าน App Groups แต่ UserDefaults.standard ครอบคลุมกรณีการใช้งานทั่วไปส่วนใหญ่ หลีกเลี่ยงการสร้างอินสแตนซ์มาตรฐานหลายตัวเพราะอาจทำให้ข้อมูลไม่สอดคล้องกัน ## มีอีก 17 คำถาม - UserDefaults สามารถจัดเก็บข้อมูลประเภทใดได้โดยตรง? - เมื่อใดที่ควรใช้ UserDefaults แทน Keychain? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ iOS อื่นๆ - [พื้นฐาน Swift](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-basics.md): 25 คำถาม, Junior - [พื้นฐานภาษา Swift](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-language-essentials.md): 15 คำถาม, Junior - [พื้นฐาน UIKit](https://sharpskill.dev/th/technologies/ios/interview-questions/uikit-fundamentals.md): 18 คำถาม, Junior - [วงจรชีวิตของ UIViewController](https://sharpskill.dev/th/technologies/ios/interview-questions/uiviewcontroller-lifecycle.md): 20 คำถาม, Junior - [วงจรชีวิตของแอปพลิเคชัน](https://sharpskill.dev/th/technologies/ios/interview-questions/app-lifecycle.md): 20 คำถาม, Junior - [Auto Layout & Constraints](https://sharpskill.dev/th/technologies/ios/interview-questions/auto-layout-constraints.md): 24 คำถาม, Mid-Level - [UITableView & UICollectionView](https://sharpskill.dev/th/technologies/ios/interview-questions/uitableview-uicollectionview.md): 25 คำถาม, Mid-Level - [พื้นฐาน SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-basics.md): 18 คำถาม, Mid-Level - [การจัดการ State ใน SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-state-management.md): 22 คำถาม, Mid-Level - [การนำทาง SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-navigation.md): 18 คำถาม, Mid-Level - [Networking & URLSession](https://sharpskill.dev/th/technologies/ios/interview-questions/networking-urlsession.md): 20 คำถาม, Mid-Level - [Codable และการแยกวิเคราะห์ JSON](https://sharpskill.dev/th/technologies/ios/interview-questions/codable-json-parsing.md): 20 คำถาม, Mid-Level - [Core Data](https://sharpskill.dev/th/technologies/ios/interview-questions/core-data.md): 22 คำถาม, Mid-Level - [การเขียนโปรแกรมเชิงโปรโตคอล](https://sharpskill.dev/th/technologies/ios/interview-questions/protocol-oriented-programming.md): 20 คำถาม, Mid-Level - [สถาปัตยกรรม MVVM](https://sharpskill.dev/th/technologies/ios/interview-questions/mvvm-architecture.md): 20 คำถาม, Mid-Level - [การแจ้งเตือนแบบ Push](https://sharpskill.dev/th/technologies/ios/interview-questions/push-notifications.md): 18 คำถาม, Mid-Level - [Unit Testing และ XCTest](https://sharpskill.dev/th/technologies/ios/interview-questions/unit-testing-xctest.md): 20 คำถาม, Mid-Level - [การทดสอบ UI](https://sharpskill.dev/th/technologies/ios/interview-questions/ui-testing.md): 18 คำถาม, Mid-Level - [Xcode และระบบ Build](https://sharpskill.dev/th/technologies/ios/interview-questions/xcode-build-system.md): 16 คำถาม, Mid-Level - [Swift Package Manager](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-package-manager.md): 16 คำถาม, Mid-Level - [Memory Management & ARC](https://sharpskill.dev/th/technologies/ios/interview-questions/memory-management-arc.md): 22 คำถาม, Senior - [Combine Framework](https://sharpskill.dev/th/technologies/ios/interview-questions/combine-framework.md): 24 คำถาม, Senior - [Concurrency & async/await](https://sharpskill.dev/th/technologies/ios/interview-questions/concurrency-async-await.md): 26 คำถาม, Senior - [iOS Design Patterns](https://sharpskill.dev/th/technologies/ios/interview-questions/ios-design-patterns.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/ios/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยและการเข้ารหัส](https://sharpskill.dev/th/technologies/ios/interview-questions/security-encryption.md): 20 คำถาม, Senior - [SwiftUI Advanced](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-advanced.md): 22 คำถาม, Senior - [สถาปัตยกรรมแอปพลิเคชัน iOS](https://sharpskill.dev/th/technologies/ios/interview-questions/ios-app-architecture.md): 22 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/ios/interview-questions/userdefaults-keychain