### Example Usage of MultiplePropertiesSelectCoordinator Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Demonstrates how to integrate the contact picker with a state-managed array of selected phone numbers. ```swift @State var selectedPhones: [CNContactProperty] = [] var body: some View { VStack { Button("Pick Phone Numbers") { showPicker = true } List(selectedPhones, id: \.identifier) { property in VStack { Text(property.value as? String ?? "") Text(property.label ?? "").font(.caption) } } } .sheet(isPresented: $showPicker) { ContactPicker( selection: $selectedPhones, propertyKey: .phoneNumbersKey ) } } ``` -------------------------------- ### Example: Multiple Email Selection Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Demonstrates using ContactPicker to select multiple email addresses via a sheet presentation. ```swift @State var selectedEmails: [CNContactProperty] = [] var body: some View { VStack { Button("Pick Multiple Emails") { showPicker = true } List(selectedEmails, id: \.value) { property in Text(property.value as? String ?? "") } } .sheet(isPresented: $showPicker) { ContactPicker( selection: $selectedEmails, propertyKey: .emailAddressesKey ) } } ``` -------------------------------- ### Install SwiftUIContacts via Swift Package Manager Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Add this dependency declaration to your Package.swift file to include the library in your project. ```swift .package(url: "https://github.com/edonv/SwiftUIContacts.git", from: "1.0.0") ``` -------------------------------- ### Usage of ContactPicker with State Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Example showing how to use ContactPicker with a @State binding to capture a selected contact. ```swift @State var selectedContact: CNContact? = nil var body: some View { VStack { if let contact = selectedContact { Text("\(contact.givenName) \(contact.familyName)") } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContact) } } ``` -------------------------------- ### Example: Multiple Phone Number Selection Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Demonstrates using ContactPicker to select multiple phone numbers via a sheet presentation. ```swift @State var selectedPhones: [CNContactProperty] = [] var body: some View { VStack { Button("Pick Multiple Phone Numbers") { showPicker = true } List(selectedPhones, id: \.value) { property in Text(property.value as? String ?? "") } } .sheet(isPresented: $showPicker) { ContactPicker( selection: $selectedPhones, propertyKey: CNContactPhoneNumbersKey ) } } ``` -------------------------------- ### MultipleContactSelectCoordinator Usage Example Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Demonstrates using the ContactPicker with a binding to an array of selected contacts. ```swift @State var selectedContacts: [CNContact] = [] var body: some View { VStack { List(selectedContacts, id: \.identifier) { contact in HStack { Text(contact.givenName) Text(contact.familyName) } } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContacts) } } ``` -------------------------------- ### SinglePropertySelectCoordinator Usage Example Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Demonstrates using the ContactPicker to select a specific property like an email address. ```swift @State var selectedEmail: CNContactProperty? = nil var body: some View { VStack { if let email = selectedEmail { Text("Email: \(email.value as? String ?? "")") } Button("Pick Email") { showPicker = true } } .sheet(isPresented: $showPicker) { ContactPicker( selection: $selectedEmail, displayedPropertyKeys: [.emailAddressesKey] ) } } ``` -------------------------------- ### Use onCompletion modifier Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Example of using the onCompletion modifier to handle the result of a contact creation or editing session. ```swift ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Contact created/saved: \(contact.givenName)") // Contact is now in the database } else { print("User cancelled without saving") } } ``` -------------------------------- ### Use onPropertySelection modifier Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Example of using the onPropertySelection modifier to intercept property taps and prevent default system actions. ```swift ContactView(for: contact, configuration: config) .onPropertySelection { property in print("User tapped: \(property.key)") // Return false to prevent default behavior return false } ``` -------------------------------- ### init(forNewContact:configuration:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Initializes a ContactView for creating a new contact, with optional pre-population data. ```APIDOC ## init(forNewContact:configuration:) ### Description Creates a ContactView for creating a new contact. The parentGroup and parentContainer properties in Configuration control where the new contact is saved. ### Signature `public init(forNewContact contact: CNContact?, configuration: Configuration)` ### Parameters - **contact** (CNContact?) - Required - Optional contact to pre-populate the new contact form; use nil for a blank form - **configuration** (Configuration) - Required - Configuration object controlling behavior and appearance ### Example ```swift var configuration = ContactView.Configuration() configuration.contactStore = CNContactStore() var body: some View { ContactView(forNewContact: nil, configuration: configuration) .onCompletion { contact in if let contact = contact { print("New contact created: \(contact.givenName)") } } } ``` ``` -------------------------------- ### Initialize ContactView with Configuration Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Configure a ContactView by setting specific properties and passing the configuration object during initialization. ```swift var configuration = ContactView.Configuration() configuration.alternativeName = "Unknown Contact" configuration.message = "Contact from email" configuration.displayedPropertyKeys = [.phoneNumbersKey, .emailAddressesKey] configuration.contactStore = CNContactStore() let contactView = ContactView(for: contact, configuration: configuration) ``` -------------------------------- ### Apply filterSelectableProperties Modifier Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Example usage of filterSelectableProperties to filter specific contact properties. ```swift ContactPicker(selection: $selectedProperty) .filterSelectableProperties(with: NSPredicate(format: "(key == 'emailAddresses') AND (value LIKE '*@apple.com')")) ``` -------------------------------- ### init(for:configuration:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Initializes a ContactView to display and optionally edit an existing contact from the contacts database. ```APIDOC ## init(for:configuration:) ### Description Creates a ContactView for displaying an existing contact. ### Signature `public init(for contact: CNContact, configuration: Configuration)` ### Parameters - **contact** (CNContact) - Required - The existing contact to display - **configuration** (Configuration) - Required - Configuration object controlling behavior and appearance ### Example ```swift let contact: CNContact = // ... fetched from contacts var configuration = ContactView.Configuration() configuration.displayedPropertyKeys = [.phoneNumbersKey, .emailAddressesKey] var body: some View { ContactView(for: contact, configuration: configuration) .allowsEditing(true) } ``` ``` -------------------------------- ### Apply filterSelectableContacts Modifier Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Example usage of filterSelectableContacts to restrict selection to contacts with phone numbers. ```swift ContactPicker(selection: $selectedContact) .filterSelectableContacts(with: NSPredicate(format: "phoneNumbers.@count > 0")) ``` -------------------------------- ### Apply filterEnabledContacts Modifier Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Example usage of filterEnabledContacts to restrict selection to contacts with email addresses. ```swift ContactPicker(selection: $selectedContact) .filterEnabledContacts(with: NSPredicate(format: "emailAddresses.@count > 0")) ``` -------------------------------- ### init(forUnknownContact:configuration:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Initializes a ContactView to display a contact that is not yet present in the contacts database. ```APIDOC ## init(forUnknownContact:configuration:) ### Description Creates a ContactView for displaying a contact that is not in the contacts database. Unknown contacts are typically contacts from external sources that the user hasn't saved. ### Signature `public init(forUnknownContact contact: CNContact, configuration: Configuration)` ### Parameters - **contact** (CNContact) - Required - The contact to display as unknown - **configuration** (Configuration) - Required - Configuration object controlling behavior and appearance ### Example ```swift let unknownContact: CNContact = // ... from external source var configuration = ContactView.Configuration() var body: some View { ContactView(forUnknownContact: unknownContact, configuration: configuration) .allowsActions(true) } ``` ``` -------------------------------- ### Configure Project Build Settings Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Deployment targets and Swift language settings for iOS, macCatalyst, and macOS. ```swift // Build Settings Minimum Deployment Target: 13.0 Swift Language Dialect: Swift 5 ``` ```swift // Build Settings Minimum Deployment Target: 13.1 Swift Language Dialect: Swift 5 Mac Catalyst: Enabled ``` ```swift // Build Settings Minimum Deployment Target: 10.15 Swift Language Dialect: Swift 5 ``` -------------------------------- ### init(selection:propertyKey:) - Multiple Properties (String) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Initializes a ContactPicker in multiple properties selection mode using a string-based property key. ```APIDOC ## init(selection:propertyKey:) ### Description Creates a ContactPicker in multiple properties selection mode, allowing selection of a specific property type from multiple contacts using a string key. ### Parameters - **selection** (Binding<[CNContactProperty]>) - Required - A binding to an array that receives the selected properties - **propertyKey** (String) - Required - A CNContact property key that will be selected for all chosen contacts (e.g., CNContactPhoneNumbersKey) ### Example ```swift @State var selectedPhones: [CNContactProperty] = [] var body: some View { ContactPicker( selection: $selectedPhones, propertyKey: CNContactPhoneNumbersKey ) } ``` ``` -------------------------------- ### Creating Custom Constants Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/types.md Demonstrates initializing a custom constant from a raw string and accessing the raw value for native API compatibility. ```swift // Use the initializer to create a custom constant from a raw string let customKey = ContactsConstant(rawValue: CNContactPhoneNumbersKey) // Access the raw value to pass to native APIs let keyString = customKey.rawValue ``` -------------------------------- ### Display File Structure Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/index.md Visual representation of the documentation directory layout. ```text output/ ├── index.md (this file) ├── quick-start.md ├── module-structure.md ├── types.md ├── api-reference/ │ ├── ContactPicker.md │ ├── ContactView.md │ ├── ContactsConstant.md │ └── Coordinators.md ``` -------------------------------- ### View Source Directory Structure Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/index.md Visual representation of the project's file hierarchy within the Sources directory. ```text Sources/SwiftUIContacts/ ├── CNContactPickerViewController/ │ ├── ContactPicker.swift (240 lines) │ │ └── ContactPicker view, SelectMode enum, Coordinator classes │ └── ContactPicker+ViewModifiers.swift (53 lines) │ └── filterEnabledContacts, filterSelectableContacts, filterSelectableProperties ├── CNContactViewController/ │ ├── ContactView.swift (179 lines) │ │ └── ContactView, Configuration, Coordinator class │ └── ContactView+ViewModifiers.swift (65 lines) │ └── onPropertySelection, onCompletion, allowsEditing, etc. └── Extensions/ └── Contacts+Constants.swift (51 lines) └── ContactsConstant with 38 property key constants ``` -------------------------------- ### init(selection:propertyKey:) - Multiple Properties (ContactsConstant) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Initializes a ContactPicker in multiple properties selection mode using a ContactsConstant for the property key. ```APIDOC ## init(selection:propertyKey:) ### Description Creates a ContactPicker in multiple properties selection mode using a ContactsConstant for the property key. ### Parameters - **selection** (Binding<[CNContactProperty]>) - Required - A binding to an array that receives the selected properties - **propertyKey** (ContactsConstant) - Required - A ContactsConstant that specifies which property type to select from multiple contacts ### Example ```swift @State var selectedEmails: [CNContactProperty] = [] var body: some View { ContactPicker( selection: $selectedEmails, propertyKey: .emailAddressesKey ) } ``` ``` -------------------------------- ### Initialize ContactView for a new contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this initializer to present a form for creating a new contact, optionally pre-populated with existing data. ```swift public init(forNewContact contact: CNContact?, configuration: Configuration) ``` ```swift var configuration = ContactView.Configuration() configuration.contactStore = CNContactStore() configuration.parentGroup = nil configuration.parentContainer = nil var body: some View { ContactView(forNewContact: nil, configuration: configuration) .onCompletion { contact in if let contact = contact { print("New contact created: \(contact.givenName)") } } } ``` -------------------------------- ### init(selection:displayedPropertyKeys:) - Single Property Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Initializes a ContactPicker configured for selecting a single property (e.g., phone number, email) from a contact. ```APIDOC ## init(selection: CNContactProperty?, displayedPropertyKeys: [ContactsConstant]?) ### Description Creates a ContactPicker in single property selection mode with optional property filters. ### Signature `public init(selection selectedProperty: Binding, displayedPropertyKeys: [ContactsConstant]? = nil) ### Parameters - **selection** (Binding) - Required - A binding that receives the selected property. - **displayedPropertyKeys** ([ContactsConstant]?) - Optional - Property keys to display in the contact detail card; if not set, all properties are shown. ### Example ```swift @State var selectedProperty: CNContactProperty? = nil ContactPicker( selection: $selectedProperty, displayedPropertyKeys: [.phoneNumbersKey] ) ``` ``` -------------------------------- ### init(selection:) - Multiple Contacts Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Initializes a ContactPicker configured for selecting multiple contacts from the system address book. ```APIDOC ## init(selection: [CNContact]) ### Description Creates a ContactPicker in multiple contacts selection mode. The selected contacts are returned via the provided binding. ### Signature `public init(selection selectedContacts: Binding<[CNContact]>) ### Parameters - **selection** (Binding<[CNContact]>) - Required - A binding to an array that receives the selected contacts. ### Example ```swift @State var selectedContacts: [CNContact] = [] ContactPicker(selection: $selectedContacts) ``` ``` -------------------------------- ### Info.plist Permissions Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Demonstrates that no Info.plist entries are required for SwiftUIContacts. ```xml ``` -------------------------------- ### Create Coordinator for ContactView Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Initializes a standard coordinator instance for the ContactView component. ```swift public func makeCoordinator() -> Coordinator { Coordinator(self) } ``` -------------------------------- ### Use CompletionHandler Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/types.md Demonstrates usage with the onCompletion view modifier to handle contact creation or cancellation. ```swift ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Contact created: \(contact.givenName)") } else { print("Cancelled") } } ``` -------------------------------- ### init(rawValue:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Initializes a new ContactsConstant instance using a raw CNContact property key string. ```APIDOC ## init(rawValue:) ### Description Creates a constant from a raw CNContact property key string. ### Signature `public init(rawValue: String)` ### Parameters - **rawValue** (String) - Required - A CNContact property key string (e.g., CNContactGivenNameKey) ### Example ```swift let customKey = ContactsConstant(rawValue: CNContactPhoneNumbersKey) ``` ``` -------------------------------- ### Initialize ContactPicker with String property key Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Defines the initializer for multiple property selection using a String key. Note that this mode is volatile and has not undergone extensive testing. ```swift public init( selection selectedProperties: Binding<[CNContactProperty]>, propertyKey: String ) ``` -------------------------------- ### init(selection:) - Single Contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Initializes a ContactPicker configured for selecting a single contact from the system address book. ```APIDOC ## init(selection: CNContact?) ### Description Creates a ContactPicker in single contact selection mode. The selected contact is returned via the provided binding. ### Signature `public init(selection selectedContact: Binding) ### Parameters - **selection** (Binding) - Required - A binding that receives the selected contact. ### Example ```swift @State var selectedContact: CNContact? = nil ContactPicker(selection: $selectedContact) ``` ``` -------------------------------- ### Initialize Multiple Contacts Picker Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Use this initializer to allow the user to select multiple contacts. The selection is bound to an array of CNContact objects. ```swift public init(selection selectedContacts: Binding<[CNContact]>) ``` ```swift @State var selectedContacts: [CNContact] = [] var body: some View { VStack { Button("Select Contacts") { showPicker = true } List(selectedContacts, id: \.identifier) { contact in Text(contact.givenName + " " + contact.familyName) } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContacts) } } ``` -------------------------------- ### Implement platform-agnostic contact views Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Use conditional compilation to handle platform availability for ContactPicker and ContactView. ```swift #if os(iOS) || targetEnvironment(macCatalyst) ContactPicker(selection: $selectedContact) #else Text("Contact picker not available on macOS") #endif ``` -------------------------------- ### Create New Contact in SwiftUI Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this pattern to present a form for creating a new contact and handling the completion callback. ```swift struct NewContactView: View { @State var isPresented = false let store = CNContactStore() var body: some View { Button("Create Contact") { isPresented = true } .sheet(isPresented: $isPresented) { var config = ContactView.Configuration() config.contactStore = store return ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Created: \(contact.givenName) \(contact.familyName)") } isPresented = false } } } } ``` -------------------------------- ### Source Reference Format Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/index.md Standard format for linking to specific source code locations. ```text Sources/SwiftUIContacts/CNContactPickerViewController/ContactPicker.swift:38-48 ``` -------------------------------- ### Initialize ContactView for an existing contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this initializer to display or edit a contact already present in the device's contact database. ```swift public init(for contact: CNContact, configuration: Configuration) ``` ```swift let contact: CNContact = // ... fetched from contacts var configuration = ContactView.Configuration() configuration.displayedPropertyKeys = [.phoneNumbersKey, .emailAddressesKey] var body: some View { ContactView(for: contact, configuration: configuration) .allowsEditing(true) } ``` -------------------------------- ### Configure ContactView Display Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Define a Configuration object to specify which contact properties are visible within a ContactView. ```swift var config = ContactView.Configuration() config.displayedPropertyKeys = [ .givenNameKey, .familyNameKey, .phoneNumbersKey, .emailAddressesKey, .organizationNameKey, .jobTitleKey ] ContactView(for: contact, configuration: config) ``` -------------------------------- ### Initialize Single Property Picker Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Use this initializer to allow the user to select a single property from a contact, with optional filtering for specific property keys. ```swift public init( selection selectedProperty: Binding, displayedPropertyKeys: [ContactsConstant]? = nil ) ``` ```swift @State var selectedProperty: CNContactProperty? = nil var body: some View { VStack { if let property = selectedProperty { Text("Selected: \(property.value)") } Button("Pick Phone Number") { showPicker = true } } .sheet(isPresented: $showPicker) { ContactPicker( selection: $selectedProperty, displayedPropertyKeys: [.phoneNumbersKey] ) } } ``` -------------------------------- ### Initialize Single Contact Picker Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Use this initializer to allow the user to select a single contact. The selection is bound to an optional CNContact object. ```swift public init(selection selectedContact: Binding) ``` ```swift @State var selectedContact: CNContact? = nil var body: some View { VStack { if let contact = selectedContact { Text("Selected: \(contact.givenName) \(contact.familyName)") } else { Text("No contact selected") } Button("Pick Contact") { showPicker = true } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContact) } } ``` -------------------------------- ### Define ContactView Configuration Structure Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md The Configuration struct defines the available customization options for a ContactView instance. ```swift public struct Configuration { public var alternativeName: String? public var message: String? public var displayedPropertyKeys: [ContactsConstant]? public var parentGroup: CNGroup? public var parentContainer: CNContainer? public var contactStore: CNContactStore? } ``` -------------------------------- ### Handle View Completion Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Process the result of a contact creation or selection flow. ```swift ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Contact saved: \(contact.givenName)") } else { print("User cancelled") } } ``` -------------------------------- ### Access Organization Properties Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Constants for accessing employment and organization details. ```swift public static let organizationNameKey: ContactsConstant ``` ```swift public static let departmentNameKey: ContactsConstant ``` ```swift public static let jobTitleKey: ContactsConstant ``` -------------------------------- ### Visualize SwiftUIContacts Module Hierarchy Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/module-structure.md A tree representation of the primary views and supporting types exported by the SwiftUIContacts module. ```text SwiftUIContacts ├── ContactPicker (iOS, macCatalyst) │ ├── SelectMode │ ├── PickerCoordinator (base) │ ├── SingleContactSelectCoordinator │ ├── MultipleContactSelectCoordinator │ ├── SinglePropertySelectCoordinator │ └── MultiplePropertiesSelectCoordinator ├── ContactView (iOS, macCatalyst) │ ├── Configuration │ ├── PropertySelectionHandler (type alias) │ ├── CompletionHandler (type alias) │ └── Coordinator └── ContactsConstant └── Static property constants for CNContact keys ``` -------------------------------- ### Add SwiftUIContacts to Framework Dependencies Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Configuration for consuming the library within a custom framework or library project. ```swift // Package.swift .package(url: "https://github.com/edonv/SwiftUIContacts.git", from: "1.0.0") let package = Package( // ... platforms: [ .iOS(.v13), .macCatalyst(.v13), ], targets: [ .target( name: "MyFramework", dependencies: [ .product(name: "SwiftUIContacts", package: "SwiftUIContacts") ] ) ] ) ``` -------------------------------- ### Initialize ContactView Coordinator Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Internal initializer used by ContactView.makeCoordinator() to link the coordinator to its parent view. ```swift internal init(_ parent: ContactView) ``` -------------------------------- ### Initialize ContactView for an unknown contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this initializer for contacts retrieved from external sources that are not yet saved in the user's contact database. ```swift public init(forUnknownContact contact: CNContact, configuration: Configuration) ``` ```swift let unknownContact: CNContact = // ... from external source var configuration = ContactView.Configuration() var body: some View { ContactView(forUnknownContact: unknownContact, configuration: configuration) .allowsActions(true) } ``` -------------------------------- ### Create New Contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Opens a sheet to create a new contact and handles the completion callback. ```swift struct NewContactView: View { @State var showContactView = false var body: some View { Button("Create Contact") { showContactView = true } .sheet(isPresented: $showContactView) { var config = ContactView.Configuration() config.contactStore = CNContactStore() return ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Created: \(contact.givenName)") } } } } } ``` -------------------------------- ### Initialize ContactsConstant Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Initializes a constant using a raw CNContact property key string. ```swift public init(rawValue: String) ``` ```swift let customKey = ContactsConstant(rawValue: CNContactPhoneNumbersKey) ``` -------------------------------- ### Configure ContactPicker Property Keys Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Use displayedPropertyKeys or propertyKey to restrict the types of contact information available for selection. ```swift ContactPicker( selection: $selectedProperty, displayedPropertyKeys: [ .phoneNumbersKey, .emailAddressesKey ] ) ``` ```swift ContactPicker( selection: $selectedPhones, propertyKey: .phoneNumbersKey ) ``` -------------------------------- ### Define SwiftUIContacts in Package.swift Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md The standard manifest configuration for including SwiftUIContacts as a dependency in a Swift Package. ```swift // swift-tools-version: 5.7 import PackageDescription let package = Package( name: "SwiftUIContacts", platforms: [ .iOS(.v13), .macCatalyst(.v13), .macOS(.v10_15) ], products: [ .library(name: "SwiftUIContacts", targets: ["SwiftUIContacts"]) ], targets: [ .target(name: "SwiftUIContacts", dependencies: []), .testTarget(name: "SwiftUIContactsTests", dependencies: ["SwiftUIContacts"]) ] ) ``` -------------------------------- ### contactViewController(_:didCompleteWith:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Handles the completion event when the contact view is dismissed. ```APIDOC ## contactViewController(_:didCompleteWith:) ### Description Called when the contact view completes and is about to be dismissed. This method dismisses the view controller and triggers the registered completion handler. ### Signature `public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?)` ### Parameters - **viewController** (CNContactViewController) - The contact view controller - **contact** (CNContact?) - The contact being created, modified, or nil if cancelled ``` -------------------------------- ### Debug ContactPicker State Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Logs the initialization state of the ContactPicker component. ```swift ContactPicker(selection: $selectedContact) .onAppear { print("ContactPicker created with mode: singleContact") } ``` -------------------------------- ### Configure ContactView Properties Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Limit the visible contact fields by setting the displayedPropertyKeys configuration. ```swift var config = ContactView.Configuration() config.displayedPropertyKeys = [ .phoneNumbersKey, .emailAddressesKey, .organizationNameKey ] ``` -------------------------------- ### Configure ContactPicker with type-safe keys Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Use ContactsConstant to define which contact properties are displayed in the picker. ```swift ContactPicker( selection: $selectedProperty, displayedPropertyKeys: [ .phoneNumbersKey, .emailAddressesKey, .postalAddressesKey, .birthdayKey ] ) ``` -------------------------------- ### Display Unknown Contact with Custom Handling Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this pattern to display an unknown contact with restricted actions and custom property selection logic. ```swift struct UnknownContactView: View { let contact: CNContact @State var isPresented = false var body: some View { Button("Show Contact") { isPresented = true } .sheet(isPresented: $isPresented) { var config = ContactView.Configuration() config.message = "Contact from email" config.displayedPropertyKeys = [.phoneNumbersKey, .emailAddressesKey] return ContactView(forUnknownContact: contact, configuration: config) .allowsActions(false) .onPropertySelection { property in print("User selected: \(property.key)") return false } } } } ``` -------------------------------- ### Using RawRepresentable with ContactsConstant Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Demonstrates initializing from a raw value, accessing the raw string, and using the constant in conditional logic. ```swift // Create from raw value let constant = ContactsConstant(rawValue: CNContactPhoneNumbersKey) // Access raw value let rawString: String = constant.rawValue // Use in switch statements and pattern matching let key = ContactsConstant.phoneNumbersKey if key.rawValue == CNContactPhoneNumbersKey { print("Phone numbers key") } ``` -------------------------------- ### Implement Multiple Property Selection Delegate Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Callback method triggered when multiple contact properties are selected. ```swift public func contactPicker(_ picker: CNContactPickerViewController, didSelectContactProperties contactProperties: [CNContactProperty]) ``` -------------------------------- ### Use PropertySelectionHandler Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/types.md Demonstrates usage with the onPropertySelection view modifier to intercept property selection. ```swift ContactView(for: contact, configuration: config) .onPropertySelection { property in print("Selected: \(property.key)") return false // Don't perform default action } ``` -------------------------------- ### Access Dates and Media Properties Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Constants for accessing dates, notes, and image data associated with a contact. ```swift public static let birthdayKey: ContactsConstant ``` ```swift public static let nonGregorianBirthdayKey: ContactsConstant ``` ```swift public static let noteKey: ContactsConstant ``` ```swift public static let imageDataKey: ContactsConstant ``` ```swift public static let thumbnailImageDataKey: ContactsConstant ``` ```swift public static let imageDataAvailableKey: ContactsConstant ``` ```swift public static let typeKey: ContactsConstant ``` -------------------------------- ### Implement Multiple Contact Selection Delegate Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Callback method triggered when multiple contacts are selected. ```swift public func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) ``` -------------------------------- ### onPropertySelection(perform:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Sets a closure to be called when the user selects a contact property. ```APIDOC ## onPropertySelection(perform:) ### Description Sets a closure to be called when the user selects a contact property. The closure must return a Bool to indicate whether the default action should be performed. ### Signature `public func onPropertySelection(perform action: ContactView.PropertySelectionHandler? = nil) -> ContactView` ### Parameters - **action** (ContactView.PropertySelectionHandler?) - Optional - Closure called with the selected `CNContactProperty`. ### Returns Updated `ContactView` with the property selection handler set. ``` -------------------------------- ### contactPicker(_:didSelectContactProperties:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Delegate method called when the user selects properties from multiple contacts in the picker. ```APIDOC ## contactPicker(_:didSelectContactProperties:) ### Description Called when the user selects properties from multiple contacts. This method updates the parent's selectedProperties binding with the array of selected properties. ### Method public func contactPicker(_ picker: CNContactPickerViewController, didSelectContactProperties contactProperties: [CNContactProperty]) ### Parameters - **picker** (CNContactPickerViewController) - The contact picker view controller - **contactProperties** ([CNContactProperty]) - Array of selected properties from one or more contacts ### Usage Notes - Returns an array of CNContactProperty objects - All selected properties are of the same type (specified in initializer) - Can select the same property type from multiple contacts - Stability Warning: This mode is volatile and subject to issues inherited from the underlying CNContactPickerViewController. ``` -------------------------------- ### Integrate ContactPicker in iOS Apps Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Basic implementation of the ContactPicker view for iOS 13.0+ targets. ```swift // Package.swift .platform(name: "ios", version: "13.0") // In your view import SwiftUIContacts struct MyView: View { @State var selectedContact: CNContact? = nil var body: some View { ContactPicker(selection: $selectedContact) } } ``` -------------------------------- ### Apply Platform Guards for Contact Views Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/module-structure.md Use these guards to ensure code containing ContactPicker or ContactView is only compiled for supported platforms. ```swift #if os(iOS) || targetEnvironment(macCatalyst) // ContactPicker and ContactView definitions #endif ``` -------------------------------- ### Select Multiple Contacts Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Implementation of a multi-contact picker using an array of CNContact objects. ```swift struct MultiContactView: View { @State var selectedContacts: [CNContact] = [] @State var showPicker = false var body: some View { VStack { Button("Pick Contacts") { showPicker = true } List(selectedContacts, id: \.identifier) { contact in Text("\(contact.givenName) \(contact.familyName)") } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContacts) } } } ``` -------------------------------- ### Configure editing permissions Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Toggles read-only mode for the contact view. ```swift public func allowsEditing(_ allows: Bool = true) -> ContactView ``` ```swift ContactView(for: contact, configuration: config) .allowsEditing(false) // Read-only mode ``` -------------------------------- ### Define Binding-Based State and Handlers Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/module-structure.md Use @Binding for selection state in ContactPicker and closures for event handling in ContactView. ```swift // ContactPicker @Binding public var selectedContact: CNContact? @Binding public var selectedContacts: [CNContact] @Binding public var selectedProperty: CNContactProperty? @Binding public var selectedProperties: [CNContactProperty] // ContactView - uses closures instead private var propertySelectionAction: PropertySelectionHandler? private var completionHandler: CompletionHandler? ``` -------------------------------- ### Initialize ContactPicker with ContactsConstant Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Defines the initializer for multiple property selection using a ContactsConstant. This mode is also considered volatile. ```swift public init( selection selectedProperties: Binding<[CNContactProperty]>, propertyKey: ContactsConstant ) ``` -------------------------------- ### Handle Property Selection Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Intercept user taps on contact properties to perform custom logic instead of default actions. ```swift ContactView(for: contact, configuration: config) .onPropertySelection { property in print("User tapped: \(property.key)") return false // Don't perform default action } ``` -------------------------------- ### allowsActions(_:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Determines whether action buttons (text message, call, FaceTime) are displayed. ```APIDOC ## allowsActions(_:) ### Description Determines whether action buttons (text message, call, FaceTime) are displayed. When disabled, only information display is available. ### Signature `public func allowsActions(_ allows: Bool = true) -> ContactView` ### Parameters - **allows** (Bool) - Optional - Whether action buttons are shown (default: true). ### Returns Updated `ContactView` with action buttons setting. ``` -------------------------------- ### Using ContactsConstant with ContactView Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/types.md Defines a configuration object to specify which contact properties are displayed within a ContactView. ```swift var configuration = ContactView.Configuration() configuration.displayedPropertyKeys = [ .givenNameKey, .familyNameKey, .phoneNumbersKey, .emailAddressesKey, .organizationNameKey ] var body: some View { ContactView(for: contact, configuration: configuration) } ``` -------------------------------- ### Access Name Properties Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Constants for accessing various parts of a contact's name. ```swift public static let namePrefixKey: ContactsConstant ``` ```swift public static let givenNameKey: ContactsConstant ``` ```swift public static let middleNameKey: ContactsConstant ``` ```swift public static let familyNameKey: ContactsConstant ``` ```swift public static let previousFamilyNameKey: ContactsConstant ``` ```swift public static let nameSuffixKey: ContactsConstant ``` ```swift public static let nicknameKey: ContactsConstant ``` -------------------------------- ### Set Fallback Name and Message Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Define default display text for contacts lacking specific information. ```swift var config = ContactView.Configuration() config.alternativeName = "Unknown Contact" config.message = "This contact is not in your contacts" ``` -------------------------------- ### Import SwiftUIContacts Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Required imports for accessing library functionality and native Contacts framework types. ```swift import SwiftUIContacts import Contacts ``` -------------------------------- ### Implement contactViewController(_:shouldPerformDefaultActionFor:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md The internal implementation that triggers the parent's propertySelectionAction closure. ```swift public func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool { parent.propertySelectionAction?(property) ?? true } ``` -------------------------------- ### Apply Platform Guards for SwiftUIContacts Views Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Ensure library components are only compiled for supported platforms by wrapping them in platform-specific conditional compilation blocks. ```swift #if os(iOS) || targetEnvironment(macCatalyst) import SwiftUI import ContactsUI public struct ContactPicker: View { // ... } #endif ``` -------------------------------- ### Implement shouldPerformDefaultActionFor Delegate Method Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Determines whether the default action should be performed when a contact property is selected. ```swift public func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool ``` -------------------------------- ### onCompletion(perform:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Sets a closure to be called when the view is dismissed. ```APIDOC ## onCompletion(perform:) ### Description Sets a closure to be called when the view is dismissed. The handler receives the contact being created or modified, or nil if the user cancelled. ### Signature `public func onCompletion(perform action: ContactView.CompletionHandler? = nil) -> ContactView` ### Parameters - **action** (ContactView.CompletionHandler?) - Optional - Closure called with the contact being created or modified. ### Returns Updated `ContactView` with the completion handler set. ``` -------------------------------- ### Implement didCompleteWith Delegate Method Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Handles the completion of the contact view controller, including dismissal and completion handler invocation. ```swift public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) ``` -------------------------------- ### Implement Cross-Platform Contact Picking Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Conditional compilation for apps targeting both iOS and macCatalyst. ```swift // MyView.swift #if os(iOS) || targetEnvironment(macCatalyst) import SwiftUIContacts #endif struct MyView: View { #if os(iOS) || targetEnvironment(macCatalyst) @State var selectedContact: CNContact? = nil var body: some View { ContactPicker(selection: $selectedContact) } #else var body: some View { Text("Contact picking not available on this platform") } #endif } ``` -------------------------------- ### Implement Single Contact Selection Delegate Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Callback method triggered when a single contact is selected. ```swift public func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) ``` -------------------------------- ### Access Phonetic Name Properties Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Constants for accessing phonetic pronunciations of name components. ```swift public static let phoneticGivenNameKey: ContactsConstant ``` ```swift public static let phoneticMiddleNameKey: ContactsConstant ``` ```swift public static let phoneticFamilyNameKey: ContactsConstant ``` ```swift public static let phoneticOrganizationNameKey: ContactsConstant ``` -------------------------------- ### Implement Single Property Selection Delegate Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Callback method triggered when a single contact property is selected. ```swift public func contactPicker(_ picker: CNContactPickerViewController, didSelect contactProperty: CNContactProperty) ``` -------------------------------- ### Define MultiplePropertiesSelectCoordinator Class Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Coordinator class for handling multiple contact property selection. ```swift public class MultiplePropertiesSelectCoordinator: PickerCoordinator ``` -------------------------------- ### Configure action button visibility Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Toggles the display of communication action buttons like call, message, or FaceTime. ```swift public func allowsActions(_ allows: Bool = true) -> ContactView ``` ```swift ContactView(for: contact, configuration: config) .allowsActions(false) // Hide call/message buttons ``` -------------------------------- ### contactViewController(_:shouldPerformDefaultActionFor:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Determines whether the default action should be performed when a user selects a contact property. ```APIDOC ## contactViewController(_:shouldPerformDefaultActionFor:) ### Description Called when the user selects a contact property, determining whether the default action should be performed. ### Signature `public func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool` ### Parameters - **viewController** (CNContactViewController) - The contact view controller - **property** (CNContactProperty) - The selected property ### Returns - **Bool** - true to perform the default action, false to suppress it. ``` -------------------------------- ### allowsEditing(_:) Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Determines whether the user can edit the contact information. ```APIDOC ## allowsEditing(_:) ### Description Determines whether the user can edit the contact information. When enabled, all properties are editable; when disabled, the view is read-only. ### Signature `public func allowsEditing(_ allows: Bool = true) -> ContactView` ### Parameters - **allows** (Bool) - Optional - Whether editing is allowed (default: true). ### Returns Updated `ContactView` with editing permission set. ``` -------------------------------- ### Display and Edit Existing Contact in SwiftUI Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this pattern to present an existing CNContact for viewing or editing within a sheet. ```swift struct ContactDetailView: View { let contact: CNContact @State var isPresented = false var body: some View { Button("View Contact") { isPresented = true } .sheet(isPresented: $isPresented) { var config = ContactView.Configuration() config.contactStore = CNContactStore() return ContactView(for: contact, configuration: config) .allowsEditing(true) .allowsActions(true) .onCompletion { _ in isPresented = false } } } } ``` -------------------------------- ### Configure Privacy Info.plist Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Required keys for iOS 17+ if accessing the contact database directly. ```xml NSPrivacyTracking NSPrivacyAccessedAPITypes NSPrivacyAccessedAPIType NSPrivacyAccessedAPICategoryContacts NSPrivacyAccessedAPITypeReasons CAC092F8-0B22-4A77-A97B-20A9BCC66156 ``` -------------------------------- ### Define property selection handler Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Sets a closure to handle contact property selection. Returning false suppresses the default system action. ```swift public func onPropertySelection(perform action: ContactView.PropertySelectionHandler? = nil) -> ContactView ``` ```swift ContactView(for: contact, configuration: config) .onPropertySelection { property in print("Selected: \(property.key)") return false // Suppress default action } ``` -------------------------------- ### Implement contactPickerDidCancel Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactPicker.md Handles the cancellation event for the contact picker. ```swift public func contactPickerDidCancel(_ picker: CNContactPickerViewController) ``` -------------------------------- ### Display Existing Contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Renders a view for an existing CNContact with editing enabled. ```swift struct ExistingContactView: View { let contact: CNContact var body: some View { var config = ContactView.Configuration() config.contactStore = CNContactStore() return ContactView(for: contact, configuration: config) .allowsEditing(true) } } ``` -------------------------------- ### Initialize PickerCoordinator Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Internal initializer used by ContactPicker.makeCoordinator() to link the coordinator to its parent view. ```swift internal init(_ parent: ContactPicker) ``` -------------------------------- ### Select a Single Contact Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/quick-start.md Implementation of a single contact picker using a state variable to store the selected CNContact. ```swift struct ContentView: View { @State var selectedContact: CNContact? = nil @State var showPicker = false var body: some View { VStack { if let contact = selectedContact { Text("Selected: \(contact.givenName) \(contact.familyName)") } else { Text("No contact selected") } Button("Pick Contact") { showPicker = true } } .sheet(isPresented: $showPicker) { ContactPicker(selection: $selectedContact) } } } ``` -------------------------------- ### Define Coordinator Class Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md The Coordinator class acts as the delegate for CNContactViewController. ```swift public class Coordinator: NSObject, CNContactViewControllerDelegate ``` -------------------------------- ### Define urlAddressesKey Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Represents the array of URLs or websites for a contact. ```swift public static let urlAddressesKey: ContactsConstant ``` -------------------------------- ### Implement contactPicker didSelect Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/Coordinators.md Handles single contact selection by updating the parent binding and dismissing the picker. ```swift public func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) public func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) { parent.selectedContact = contact } ``` -------------------------------- ### Unit Test Contact Constants Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/platform-guide.md Verifies internal contact key mappings using XCTest. ```swift import XCTest @testable import SwiftUIContacts class SwiftUIContactsTests: XCTestCase { func testContactsConstant() { let key = ContactsConstant.phoneNumbersKey XCTAssertEqual(key.rawValue, CNContactPhoneNumbersKey) } } ``` -------------------------------- ### Define instantMessageAddressesKey Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Represents the array of instant messaging addresses for a contact. ```swift public static let instantMessageAddressesKey: ContactsConstant ``` -------------------------------- ### Define CompletionHandler Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Use this closure to handle the final state of the contact after the user finishes editing or creating it. ```swift public typealias CompletionHandler = (_ contact: CNContact?) -> Void ``` -------------------------------- ### Implement makeCoordinator for SelectMode Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/types.md The selectMode property is used within makeCoordinator to instantiate the appropriate delegate coordinator. ```swift public func makeCoordinator() -> CNContactPickerDelegate { switch selectMode { case .singleContact: return SingleContactSelectCoordinator(self) case .multipleContacts: return MultipleContactSelectCoordinator(self) case .singleProperty: return SinglePropertySelectCoordinator(self) case .multipleProperties: return MultiplePropertiesSelectCoordinator(self) } } ``` -------------------------------- ### Define datesKey Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Represents the array of important dates for a contact. ```swift public static let datesKey: ContactsConstant ``` -------------------------------- ### Use phoneNumbersKey in ContactPicker Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactsConstant.md Configures the ContactPicker to display phone numbers. ```swift ContactPicker( selection: $selectedProperty, displayedPropertyKeys: [.phoneNumbersKey] ) ``` -------------------------------- ### Define completion handler Source: https://github.com/edonv/swiftuicontacts/blob/main/_autodocs/api-reference/ContactView.md Sets a closure to execute upon view dismissal, receiving the contact object or nil if cancelled. ```swift public func onCompletion(perform action: ContactView.CompletionHandler? = nil) -> ContactView ``` ```swift ContactView(forNewContact: nil, configuration: config) .onCompletion { contact in if let contact = contact { print("Contact saved: \(contact.givenName)") } else { print("User cancelled") } } ```