Gives API access to all Algolia functionality, settings, advanced features, and ML/AI products
Pure cross-platform Swift client
Available via Cocoapods, Swift Package Manager, Carthage
Uses Result type and Codable protocol
Background retry strategy to ensure uptime
Seamless batching via iterators to optimize number of network calls
Zero downtime reindexing feature
Injectable HTTP client
Compatible with Swift 5.0+ and uses latest Swift features such as keypaths, Result type and Codable structures
Supports all platforms that Swift supports (iOS, macOS, watchOS, tvOS, Linux)
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)")
}
}