Core Data의 지속성 + Swift의 모던 연속성
특징
- SwiftUI와 동일하게 모든 것이 코드로 작동됨
- Macro를 활용하여 정의
- Model macro를 통해 어떠한 모델 클래스든 저장가능한 형태로 생성
- @Attiribute, @Relationship 과 같은 매크로 활용
- ModelContext 클래스를 통해 입력, 업데이트, 삭제, 인스턴스화 그리고 저장되지 않은 정보를 디스크에 저장까지 가능
- SwiftUI 뷰에 모델을 표기할 때는 Query 프로퍼티 랩퍼와 predicate 혹은 fetch descriptor 활용
- modelContainer, modelContext를 통해 SwiftUI 뷰에서 ModelContext에 엑세스 가능
- migration => Schema와 SchemaMigrationPlan 을 통해 이전 가능
공부할 키워드
- Model macro
- @Attiribute, @Relationship
- ModelContext
- Query
- modelContainer, modelContext
- Schema
- SchemaMigrationPlan
- FetchDescriptor
참고사항 from WWDC23 비디오
하나씩 정리해갈 내용이지만, 영상을 통해 조금 정리한 내용을 밑에 정리한다. (놓친 부분도 많다,,)
Macros
@Attribute(.unique) : unique name을 가질 수 있도록 함
@Attribute(oringialName: "") var newName: Type : entity의 이름을 변경할 때
@Relationship(.cascade) : 관계형으로 메인 모델이 삭제될 때 같이 삭제
@Transient : ??
Evolving schemas 순서 (Migration)
- VersionedSchema : 버전들을 캡슐화
- SchemaMigrationPlan : 순서대로 스키마 형성
- migrating stage 결정 (Lightweight or Custom)
- migrationPlan
현재까지 확인한 SwiftData WWDC23 영상:
- Meet SwiftData
- Migrate to SwiftData
- Model your schema with SwiftData
- Dive deeper into SwiftData
공식문서 링크
'IOS 개발지식 > 개발자 공식문서' 카테고리의 다른 글
[Technology] SiriKit (0) | 2023.06.24 |
---|---|
[Framework] ActivityKit (0) | 2023.06.24 |
[Framework] WidgetKit (0) | 2023.06.23 |