- context(managed object) <—> coordinator(persistent store) <—-> SQLite
- The managed object context keeps track of its managed objects and all the changes you make to them
- NSPersistentContainer : A container that encapsulates the Core Data stack in your application. 스택 세팅을 위한 helper class
- A programmatic representation of the .xcdatamodeld file describing your objects.
- database schema 역할
- The abstract base class for all Core Data persistent stores.
- atomic store : 데이터를 읽고 쓰기 전에 deserialize 해서 메모리에 로드해야함 (XML, Binary, InMemory)
- non atomic store : 바로 메모리에 로드 가능 (SQLite)
- NSIncrementalStore : An abstract superclass defining the API through which Core Data communicates with a store. 이걸 상속해서 커스텀 스토어 생성 가능
- A coordinator that uses the model to help contexts and persistent stores communicate.
- An object space that you use to manipulate and track changes to managed objects.
- managed object의 life cycle 관리
- A context is not thread-safe. The same goes for a managed object: You can only interact with contexts and managed objects on the same thread in which they were created.
- A container that encapsulates the Core Data stack in your application.
- 위의 4가지 스택을 모두 포함
- context 만 public 으로 접근 가능
- class CoreDataStack 생성해서 스택을 세팅한다
- 모델 파일을 생성할 때 코어데이터 템플릿을 생성하고 확장자를 swift가 아닌 xcdatamodeld 로 해야한다
- entity 간의 관계는 relationship 에서 설정가능
- Editor -> Create NSManagedObject subclass 를 선택하여 각 entity의 모델파일 생성