Posts

Post marked as solved
1 Replies
602 Views
So I only recently uncovered the Contacts Framework through this video: https://youtu.be/sHKir2ZMk5Q. As such I'm not yet accustomed to the API. Basically my main problem is that I can't seem to find a way to access the name of the group a CNContact is in. The only support I can find is in Apple's own documentation, which isn't very helpful. if someone could point me in the right direction towards how to print the group name, I would be very grateful. My code is below, Cheers // ModelData.swift // B-Day import Foundation import Contacts import SwiftUI struct Contact: Identifiable { let id = UUID() let category: String let firstName: String let lastName: String let birthday: DateComponents? } func fetchAllContacts() async -> [Contact] { var contacts = [Contact]() let store = CNContactStore() let keys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactBirthdayKey, CNContactIdentifierKey, CNGroupNameKey] as [CNKeyDescriptor] let fetchRequest = CNContactFetchRequest (keysToFetch: keys) do { try store.enumerateContacts(with: fetchRequest, usingBlock: { contact, result in //this should print the name of the contact's group print(contact.groupName) contacts.append(Contact(category: contact.groupName, firstName: contact.givenName, lastName: contact.familyName, birthday: contact.birthday)) }) } catch { print("Error") } return contacts }
Posted
by The-Wolf.
Last updated
.
Post not yet marked as solved
0 Replies
674 Views
Hi All, I'm quite new to swift and am wondering why I am receiving a "Trailing closure passed to parameter of type 'Visibility' that does not accept a closure" error on the .toolbar{ line I Have Supplied My Code Below Thanks in Advance, Josh struct HomeView: View {     var body: some View {         Text("Home")             .toolbar{                 ToolbarItem(placement: .navigationBarLeading)                 Button(action: NavigationLink(destination: AccountView()), label: Image(systemName: "gearshape"))                 ToolbarItem(placement: .principal) { Text("Welcome").font(.title)                 }                 ToolbarItem(placement: .navigationBarTrailing)                 Button(action: NavigationLink(destination: AccountView()), label: Image(systemName: "person.circle"))             }             .navigationBarTitleDisplayMode(.inline)     } } struct HomeView_Previews: PreviewProvider {     static var previews: some View {         HomeView()     } }```
Posted
by The-Wolf.
Last updated
.