Contact Search via API

The ContactsManager SDK provides powerful contact search capabilities through its API layer. This section explains the available search endpoints and their usage.

The searchContacts method provides full-featured search functionality with pagination support:

// Perform a comprehensive search with pagination
let (contacts, totalCount) = try await ContactSearchService.shared.searchContacts(
    query: "john",
    searchFields: [.name, .email, .phone],
    offset: 0,
    limit: 50
)

For real-time search-as-you-type scenarios, use the optimized quickSearch method:

// Quick search optimized for UI interactions
let results = try await ContactSearchService.shared.quickSearch("jo")

You can target specific contact fields in your search:

// Search in specific fields
let (contacts, total) = try await ContactSearchService.shared.searchContacts(
    query: "developer",
    searchFields: [.organization, .jobTitle]
)

The following fields can be included in search operations:

  • name: First, middle, last name, nickname
  • email: Email addresses
  • phone: Phone numbers
  • address: Physical addresses
  • organization: Company name and department
  • notes: Contact notes and additional information

Contact Search UI

The ContactsManager SDK provides a built-in search and select UI that you can easily integrate into your app.

Using the Contact Picker

Installation

The contact picker is included in the ContactsManager SDK for iOS. No additional installation is required.

Configuration

Configure the picker using ContactSelectionOptions:

let options = ContactSelectionOptions(
    selectionMode: .multiple,  // .single or .multiple
    fieldType: .any,          // .phone, .email, .notes, or .any
    maxSelectionCount: 5      // Optional limit for multiple selection
)

Usage

Present the contact picker from your view controller:

ContactsManagerUI.getInstance().searchContacts(
    from: viewController,
    options: options
) { result in
    switch result {
    case .success(let contacts):
        // Handle selected contacts
        print("Selected \(contacts.count) contacts")
    case .failure(let error):
        // Handle error
        print("Error: \(error.localizedDescription)")
    }
}

Features

  • Beautiful native UI following iOS design guidelines
  • Real-time search across all contact fields
  • Support for single or multiple selection
  • Field-type filtering (phone, email, etc.)
  • Selection limit enforcement
  • Customizable appearance
  • Automatic permission handling

Contact Selection Options

The ContactSelectionOptions struct/object allows you to configure:

  • selectionMode: Single or multiple contact selection
  • fieldType: Filter contacts by field type (phone, email, any)
  • maxSelectionCount: Maximum number of contacts that can be selected

Thread Safety

Overview

The Contact model in Swift is built on SwiftData and has important thread safety considerations that must be followed carefully.

Key Thread Safety Rules

  • Contact objects must be accessed on the thread where they were created
  • Search methods return Contact objects that are bound to the main thread
  • Any modifications to Contact objects must be performed on the main thread
  • Background operations should use @MainActor or dispatch to the main thread for Contact updates

Best Practices

  • Always use @MainActor where accessing Contact objects