# Core Data (iOS) > Core Data stack, NSManagedObject, fetch request, ความสัมพันธ์, การ migration, ประสิทธิภาพ - 22 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: iOS](https://sharpskill.dev/th/technologies/ios/interview-questions.md) ## 1. NSPersistentContainer ใน Core Data คืออะไร? **คำตอบ** NSPersistentContainer ห่อหุ้ม Core Data stack ทั้งหมดรวมถึง NSPersistentStoreCoordinator, NSManagedObjectContext และ NSPersistentStore ช่วยให้การกำหนดค่าเริ่มต้นง่ายขึ้นด้วยการจัดการการตั้งค่าโดยอัตโนมัติและลดโค้ด boilerplate เมื่อเทียบกับวิธีแบบแมนนวลเดิม การใช้ NSPersistentContainer เป็นแนวทางที่แนะนำตั้งแต่ iOS 10 สำหรับการตั้งค่า Core Data อย่างรวดเร็วและ thread-safe ## 2. บทบาทหลักของ NSManagedObjectContext คืออะไร? **คำตอบ** NSManagedObjectContext ทำหน้าที่เป็น scratch pad ในหน่วยความจำระหว่างแอปพลิเคชันและชั้นจัดเก็บข้อมูลแบบถาวร มันจัดการการดำเนินการ CRUD ติดตามการเปลี่ยนแปลงทั้งหมดด้วย undo/redo และประสานงานการบันทึกไปยัง persistent store context ผูกกับ queue เฉพาะและต้องไม่แชร์ระหว่าง thread ใช้ perform() สำหรับการโต้ตอบที่ thread-safe ทุกครั้ง ## 3. NSManagedObject คืออะไร? **คำตอบ** NSManagedObject เป็นคลาสพื้นฐานสำหรับอ็อบเจกต์แบบถาวรทั้งหมดใน Core Data มันแทน instance ที่ไม่ซ้ำกันของ entity ที่กำหนดไว้ในโมเดลข้อมูลพร้อม objectID ที่ไม่ซ้ำกัน NSManagedObject จัดการพร็อพเพอร์ตี้ผ่าน KVC ความสัมพันธ์แบบสองทาง และสถานะอ็อบเจกต์ (inserted, updated, deleted) ภายใน context โดยอัตโนมัติ การสร้าง subclass ของ NSManagedObject ช่วยให้เพิ่ม business logic ได้ ## มีอีก 19 คำถาม - จะเริ่มต้น NSFetchRequest เพื่อดึง entity อย่างไร? - อ็อบเจกต์ใดรับผิดชอบการสื่อสารกับชั้นจัดเก็บข้อมูล? สมัครฟรี: 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 - [UserDefaults & Keychain](https://sharpskill.dev/th/technologies/ios/interview-questions/userdefaults-keychain.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 - [การเขียนโปรแกรมเชิงโปรโตคอล](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/core-data