Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 475 Bytes

core-data-background-context.md

File metadata and controls

22 lines (19 loc) · 475 Bytes

core data background context

let context = persistentContainer.newBackgroundContext()
context.automaticallyMergesChangesFromParent = true

context.perform {
  let howMany = 999
  for index in 1...howMany{
    let person = Person(context: context)
    person.firstName = "First name \(index)"
    person.lastName = "First name \(index)"
  }
  do{
    try context.save()
    DispatchQueue.main.async{completion()}
  } catch {
    // catch the errors here
  }

}