Skip to content

CoreData 학습

KYHyeon edited this page Nov 18, 2020 · 2 revisions

11월 17일 CoreData 학습

오늘의 주제: Core Data

학습한 내용을 정리하거나 참고자료를 올려주세요😀

1 2
// Core Data save

// Setting
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext

// 저장1
let person = Person(context: context)

person.age = 1
person.name = "name"
person.person = "person"

try? context.save()

// 저장2
let entity = NSEntityDescription.entity(forEntityName: "Person", in: context)
if let entity = entity {
    let model = NSManagedObject(entity: entity, insertInto: context)
    model.setValue(123, forKey: "age")
    model.setValue("n", forKey: "name")
    model.setValue("p", forKey: "person")
}
try? context.save()
// 출력
func fetchContact() {
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let context = appDelegate.persistentContainer.viewContext
    do {
        let contact = try context.fetch(Person.fetchRequest()) as! [Person]
        contact.forEach {
            print($0.name)
        }
    } catch {
        print(error.localizedDescription)
    }
}
// 삭제
let request2: NSFetchRequest<Person> = Person.fetchRequest()
deleteAll(request: request2)

func deleteAll<T: NSManagedObject>(request: NSFetchRequest<T>) {
    let request: NSFetchRequest<NSFetchRequestResult> = T.fetchRequest()
    let delete = NSBatchDeleteRequest(fetchRequest: request)
    try? self.context.execute(delete)
}

Map SDK를 활용한 POI Clustering Interaction Dev

기획서

🍎 iOS

😀 이것만은 지켜요🤝

Ground Rules
Code Convention
Branch Strategy
Commit Message

데일리 스크럼

Week 1
Week 2
Week 3
Week 4
Week 5

TroubleShooting

트러블슈팅

학습

Clone this wiki locally