Skip to content

Commit

Permalink
fixed double items bug (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoeriVD authored Jul 24, 2024
1 parent a876db1 commit 804d4ee
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Next calls/Data/ContactStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class ContactStore{
guard isAvailable else {
throw ErrorMessages.accessDenied
}
let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactNicknameKey]
let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactNicknameKey, CNContactOrganizationNameKey]
let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
var contacts = [CNContact]()
try cnStore.enumerateContacts(with: request){(contact, stop) in
Expand Down
12 changes: 11 additions & 1 deletion Next calls/Data/ReminderStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ final class ReminderStore{
guard isAvailable else {
throw ErrorMessages.accessDenied
}
let predicate = ekStore.predicateForReminders(in: nil)
// filter on specific list
let calendars = ekStore.calendars(for: .reminder)
let nextActions = calendars.first { cal in
return cal.title == "Volgende acties"
}
guard let nextActions else {
throw ErrorMessages.noNextActionList
}

let predicate = ekStore.predicateForReminders(in: [nextActions])

let ekReminders = try await ekStore.reminders(matching: predicate)
let reminders: [Reminder] = try ekReminders
.filter{reminder in !reminder.isCompleted }
Expand Down
26 changes: 16 additions & 10 deletions Next calls/Messages/ErrorMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,36 @@ enum ErrorMessages: LocalizedError {
case accessRestricted
case noTitle
case noPhone
case noNextActionList
case unknown

var errorDescription: String? {
switch self {
case .failedReadingReminders:
return NSLocalizedString(
"Failed to read reminders.", comment: "failed reading reminders error description")
"Failed to read reminders.",
comment: "failed reading reminders error description")

case .accessDenied:
return NSLocalizedString(
"The app doesn't have permission to read reminders.",
comment: "access denied error description")
case .accessRestricted:
return NSLocalizedString(
"This device doesn't allow access to reminders.",
comment: "access restricted error description")
return NSLocalizedString(
"This device doesn't allow access to reminders.",
comment: "access restricted error description")
case .noTitle:
return NSLocalizedString(
"This reminder does not have a title.",
comment: "Unable to determine if it is about a call.")
return NSLocalizedString(
"This reminder does not have a title.",
comment: "Unable to determine if it is about a call.")
case .noPhone:
return NSLocalizedString(
"This reminder does not have a phone number.",
comment: "Unable to determine if it is about a call.")
return NSLocalizedString(
"This reminder does not have a phone number.",
comment: "Unable to determine if it is about a call.")
case .noNextActionList:
return NSLocalizedString(
"Reminders does not have a list called Volgende acties",
comment: "Hardcoded list Volgende acties is a requirement.")
case .unknown:
return NSLocalizedString("An unknown error occurred.", comment: "unknown error description")
}
Expand Down
5 changes: 4 additions & 1 deletion Next calls/Model/Contact+CNContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ extension Contact {
"\(contact.familyName), \(contact.givenName)",
"\(contact.givenName) \(contact.familyName)",
"\(contact.givenName), \(contact.familyName)",
contact.nickname
contact.nickname,
contact.organizationName
].compactMap{index in
return index.lowercased().trimmingCharacters(in: CharacterSet.whitespaces)
}.filter{ index in
return index != "," && index != ""
}

phone = try Phone(with: contact.phoneNumbers.first?.value)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=YoeriVD_Next-calls&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=YoeriVD_Next-calls)


## Next calls

This is the beginning of a native iOS app that looks through your reminders and selects only those that are about calls, and makes these available through carplay

## Good to know

This is a personal project, it is not published to the store (and might never be).

0 comments on commit 804d4ee

Please sign in to comment.