Skip to content

Commit

Permalink
Fix EventKit and Contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 11, 2024
1 parent 0ba8011 commit 05a5d83
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

#if canImport(EventKit)
import EventKit
@preconcurrency import EventKit
#endif
import Factory
import OversizeCalendarService
Expand All @@ -14,13 +14,13 @@ import OversizeModels
import SwiftUI

#if !os(tvOS)
public enum CreateEventType: Equatable {
public enum CreateEventType: Equatable, @unchecked Sendable {
case new(Date?, calendar: EKCalendar?)
case update(EKEvent)
}

@MainActor
public class CreateEventViewModel: ObservableObject {

public class CreateEventViewModel: ObservableObject, @unchecked Sendable {
@Injected(\.calendarService) private var calendarService: CalendarService
@Injected(\.locationService) private var locationService: LocationServiceProtocol

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

#if canImport(Contacts) && canImport(EventKit)
import Contacts
@preconcurrency import Contacts
import EventKit
#endif
import Factory
Expand All @@ -29,9 +29,9 @@ import SwiftUI
func fetchData() async {
state = .loading
let _ = await contactsService.requestAccess()
do {

let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactEmailAddressesKey, CNContactThumbnailImageDataKey]
let result = try await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
let result = await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
switch result {
case let .success(data):
log("✅ CNContact fetched")
Expand All @@ -40,9 +40,7 @@ import SwiftUI
log("❌ CNContact not fetched (\(error.title))")
state = .error(error)
}
} catch {
state = .error(.custom(title: "Not contacts"))
}

}

func getContactFromEmail(email: String, contacts: [CNContact]) -> CNContact? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

#if canImport(Contacts)
import Contacts
@preconcurrency import Contacts
#endif
import Factory
import OversizeContactsService
Expand All @@ -24,9 +24,9 @@ import SwiftUI
func fetchData() async {
state = .loading
let _ = await contactsService.requestAccess()
do {

let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactEmailAddressesKey, CNContactThumbnailImageDataKey]
let result = try await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
let result = await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
switch result {
case let .success(data):
log("✅ CNContact fetched")
Expand All @@ -35,9 +35,7 @@ import SwiftUI
log("❌ CNContact not fetched (\(error.title))")
state = .error(error)
}
} catch {
state = .error(.custom(title: "Not contacts"))
}

}

func getContactFromEmail(email: String, contacts: [CNContact]) -> CNContact? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

#if canImport(Contacts)
import Contacts
@preconcurrency import Contacts
#endif
import Factory
import OversizeContactsService
Expand All @@ -26,9 +26,9 @@ import SwiftUI
let status = await contactsService.requestAccess()
switch status {
case .success:
do {

let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactEmailAddressesKey, CNContactThumbnailImageDataKey]
let result = try await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
let result = await contactsService.fetchContacts(keysToFetch: keys as [CNKeyDescriptor])
switch result {
case let .success(data):
log("✅ CNContact fetched")
Expand All @@ -37,9 +37,7 @@ import SwiftUI
log("❌ CNContact not fetched (\(error.title))")
state = .error(error)
}
} catch {
state = .error(.contacts(type: .unknown))
}

case let .failure(error):
state = .error(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import SwiftUI

#if !os(watchOS)
@MainActor
class AddressPickerViewModel: NSObject, ObservableObject {
class AddressPickerViewModel: NSObject, ObservableObject {
@Injected(\.locationService) var locationService: LocationServiceProtocol

@Published var locationResults: [MKLocalSearchCompletion] = .init()
Expand Down Expand Up @@ -60,7 +60,7 @@ import SwiftUI
}
}

extension AddressPickerViewModel: MKLocalSearchCompleterDelegate {
extension AddressPickerViewModel: @preconcurrency MKLocalSearchCompleterDelegate {
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
currentPromise?(.success(completer.results))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

public enum LocalNotificationTime: CaseIterable, Equatable, Identifiable {
public enum LocalNotificationTime: CaseIterable, Equatable, Identifiable, @unchecked Sendable {
case oneMinuteBefore, fiveMinutesBefore, tenMinutesBefore, thirtyMinutesBefore, oneHourBefore, twoHoursBefore, oneDayBefore, twoDaysBefore, oneWeekBefore

public var title: String {
Expand Down Expand Up @@ -58,5 +58,5 @@ public enum LocalNotificationTime: CaseIterable, Equatable, Identifiable {
title
}

public static var allCases: [LocalNotificationTime] = [.oneMinuteBefore, .fiveMinutesBefore, .tenMinutesBefore, .thirtyMinutesBefore, .oneHourBefore, .twoHoursBefore, .oneDayBefore, .twoDaysBefore, .oneWeekBefore]
public static let allCases: [LocalNotificationTime] = [.oneMinuteBefore, .fiveMinutesBefore, .tenMinutesBefore, .thirtyMinutesBefore, .oneHourBefore, .twoHoursBefore, .oneDayBefore, .twoDaysBefore, .oneWeekBefore]
}

0 comments on commit 05a5d83

Please sign in to comment.