I'm getting a memory error when I try and access the keyboard in another view, that has nothing to do with fetching contacts. The view I am in allows one to update information via TextField
and the other view, Contact.swift
is where I get the crash.
In any event, I'm getting a black screen before crashing and seeing these errors.
[ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke
Error communicating with XPC Service: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named
Here's the code:
static func fetch(_ completion: @escaping(Result<[Contact], Error>) -> Void) {
let containerID = CNContactStore().defaultContainerIdentifier
let predicate = CNContact.predicateForContactsInContainer(withIdentifier: containerID())
let keysToFetch = [
CNContactImageDataKey,
CNContactImageDataAvailableKey,
CNContactThumbnailImageDataKey,
CNContactGivenNameKey,
CNContactFamilyNameKey,
CNContactPhoneNumbersKey,
CNContactEmailAddressesKey
] as [CNKeyDescriptor]
do {
let contacts = try CNContactStore().unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
completion(.success(contacts.map({ .init(contact: $0)})))
} catch {
completion(.failure(error))
}
}
I'm specifically crashing on the line
let contacts = try CNContactStore().unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
with unifiedContacts
alone underlined as the issue. I can't even tap on the tab, now. It either crashes Xcode or my app, entirely.
UPDATE
So the line:
let contacts = try CNContactStore().unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
is what's crashing, but only when I use this predicate
.predicateForContactsInContainer(withIdentifier: containerID())
There are different predicates I can use to limit the fetch, such as class func predicateForContacts(matchingName name: String) -> NSPredicate
.
I believe the issue is I am fetching all the contacts at once. Yes, I am doing so on a background thread, but it seems my app cannot handle fetching all my contacts at once in the way I am doing so.
UNRESOLVED
I still haven't solved this issue. I am using instruments and have 6000+ leaks that I believe are coming from fetching contacts. Can anyone describe what this means? I know it's a retain cycle but without anything in the call stack, I have no idea where to begin so I'm basically beginning everywhere.
Of course there is no stack trace. May have to rearchitect the app.