mobile-ios/CovidSafe/Encounter+EncounterRecord.swift

32 lines
875 B
Swift
Raw Normal View History

2020-05-08 07:49:14 +00:00
//
// Encounter+EncounterRecord.swift
// CovidSafe
//
// Copyright © 2020 Australian Government. All rights reserved.
//
import UIKit
import CoreData
extension EncounterRecord {
func saveToCoreData() {
DispatchQueue.main.async {
guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName: "Encounter", in: managedContext)!
let encounter = Encounter(entity: entity, insertInto: managedContext)
encounter.set(encounterStruct: self)
do {
try managedContext.save()
} catch {
print("Could not save. \(error)")
}
}
}
}