COVIDSafe code from version 1.4 (#3)

This commit is contained in:
COVIDSafe Support 2020-05-26 17:13:26 +10:00 committed by GitHub
parent 56c93f2079
commit b2e0c5b34c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 6865 additions and 481 deletions

View file

@ -19,12 +19,13 @@ final class ContactViewController: UIViewController {
}
func fetchContacts() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
guard let persistentContainer =
EncounterDB.shared.persistentContainer else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let managedContext = persistentContainer.viewContext
let fetchRequest = Encounter.fetchRequestForRecords()
let sortByContactId = NSSortDescriptor(key: "msg", ascending: false)
let sortByContactId = NSSortDescriptor(key: "timestamp", ascending: false)
fetchRequest.sortDescriptors = [sortByContactId]
fetchedResultsController = NSFetchedResultsController<Encounter>(fetchRequest: fetchRequest, managedObjectContext: managedContext, sectionNameKeyPath: nil, cacheName: nil)
fetchedResultsController?.delegate = self
@ -44,11 +45,11 @@ final class ContactViewController: UIViewController {
}
var contactCounts: [String: Int] = [:]
for encounter in encounters {
if encounter.msg != nil {
if contactCounts[encounter.msg!] == nil {
contactCounts[encounter.msg!] = 0
if encounter.remoteBlob != nil {
if contactCounts[encounter.remoteBlob!] == nil {
contactCounts[encounter.remoteBlob!] = 0
}
contactCounts[encounter.msg!]! += 1
contactCounts[encounter.remoteBlob!]! += 1
}
}
var contactTuples = contactCounts.map { ($0.key, $0.value) }