Get started

INSTALL


        
          
            

let package = Package(
    dependencies: [
        .package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.0.0")
    ],
    // ...
)

INDEX


        
          
            

struct Contact: Encodable {
  let objectID: ObjectID
  let firstname: String
  let lastname: String
}

let contacts: [Contact] = [
  .init(objectID: "myID1", firstname: "Jimmie", lastname: "Barninger"),
  .init(objectID: "myID2", firstname: "Warren", lastname: "Speach"),
]

let replacements = contacts.map {($0.objectID, $0) }

index.replaceObjects(replacements: replacements) { result in
  if case .success(let response) = result {
    print("Response: \(response)")
  }
}

SEARCH


        
          
            

let index = client.index(withName: "contacts")
index.search(query: "s") { result in
  if case .success(let response) = result {
    print("Response: \(response)")
  }
}

var query = Query("s")
query.attributesToRetrieve = ["firstname", "lastname"]
query.hitsPerPage = 50
index.search(query: query) { result in
  if case .success(let response) = result {
    print("Response: \(response)")
  }
}

Enable anyone to build great Search & Discovery