Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Summary
데이터저장(CoreData 활용 기본) #7
✨ Description
CoreData 세팅 및 기본
1.
.xcdatamodeld파일 추가.xcdatamodeld파일이 생성된다..xcdatamodeld파일을 생성할 수 있다.2. Entity, Attribute 정의
CoreData에서 Entity는 class나 struct, Attribute는 Entity에 대한 프로퍼티라고 생각할 수 있다.
3. Core Data Model로부터 class 생성
4. Core Data Stack Setting
📑 Core Data Stack이란 앱의 모델 레이어를 협력해서 서포트하는 객체들로 Core Data를 사용하기 위해서는 Core Data Stack이 반드시 필요하다.코어 데이터 스택 구조
NSPersistentContainer클래스가NSManagedObjectModel,NSManagedObjectContext,NSPersistentStoreCoordinator를 프로퍼티로 가지고 있다5. Core Data Stack 추가
6. 뷰 연결하기
ProjectNameApp.swift 파일에서 싱글톤으로 만든 persistentController를 Environment로 ContentView에 전달한다.
CoreData를 사용할 파일에 접근(또는 생성하여) Environment로 제공된 context에 접근한다.
저장된 데이터를 가져오기 위해 @fetchrequest Property Wrapper를 사용해서 데이터를 가져온다.
CRUD 메소드를 구현한다.
추가 제거를 위한 간단한 UI를 구현한다.
전체 코드
reference
📸 Screenshot
🗒️ Review Point