반응형
Section19. 252) Core Data Fundamental
| OOP World | Core Data World | Database World |
| Class | Entity | Table |
| Property | Attribute | Field |
전체: Table, Class, Entity
| Attributes (property) | |||
| Buyers | Address | Number | Who to Invoice |
| Walmart | 702.S.W. Street, Bentonville.... | 1-800-925-6278 | sam@walmart.com |
| Tesco | .... | ||
| Whole Foods | ..... |
행: NSManagedObject
Table안에 들어있는 각각의 요소들은 Core Data.
NSManagedObject의 예시:

Item 의 title, done (각 행을 말함).
Core Data - CRUD
SQLite 로 확인

//CRUD 중에 C (CREATE)
func saveItems() {
do {
try context.save()
} catch {
print("Error saving context \(error)")
}
self.tableView.reloadData()
}
//CRUD 중에 R (READ)
앱을 완전히 종료했다가 다시 켜더라도 데이터들을 불러온다.
func loadItems() {
let request : NSFetchRequest<Item> = Item.fetchRequest()
do {
itemArray = try context.fetch(request)
} catch {
print("Error fetching data from context \(error)")
}
}
반응형
'iOS > iOS Swift Udemy - AngelaYu' 카테고리의 다른 글
| Section13. 143) 다크모드 및 벡터 Assets 작업. (0) | 2022.12.13 |
|---|---|
| Section19 247) searchbar에서 검색 취소 클릭시 키보드 내리기 (0) | 2022.11.01 |
| Section19. 249) CoreData (0) | 2022.10.29 |
| Section19. 248) 데이터베이스 소개 (0) | 2022.10.29 |
| Section19. 246) NSCoder로 데이터 인코딩/디코딩(save & load) (0) | 2022.10.28 |