Skip to content

Migration guide from Objective C to Swift API Client

Thibault Deutsch edited this page Jul 3, 2015 · 10 revisions

This guide explains how to migrate your code from the Objective-C API Client to the Swift API Client.

If you have any issue, please contact our team at [email protected].

Migrate your code to Swift API Client

Where to find the Swift API Client?

The latest version can always be found on GitHub and CocoaPods.

Objective-C API Client

pod 'AlgoliaSearch-Client', '~> 3.5'

Swift API Client

use_frameworks!
pod 'AlgoliaSearch-Client-Swift', '~> 1.4'

Initialization

Objective-C API Client

#import "ASAPIClient.h"

ASAPIClient *apiClient = [ASAPIClient apiClientWithApplicationID:@"YourApplicationID" apiKey:@"YourAPIKey"];

Swift API Client

#import "AlgoliaSearch-Swift.h"

Client *apiClient = [Client clientWithAppID:@"YourApplicationID" apiKey:@"YourAPIKey"];

Callback conventions

Objective-C API Client

[index search:query success:^(ASRemoteIndex *index, ASQuery *query, NSDictionary *result) {
    // no error
} failure:^(ASRemoteIndex *index, ASQuery *query, NSString *errorMessage) {
    // error
}];

Swift API Client

[index search:query block:^(NSDictionary * content, NSError * error) {
    // error `nil` or `NSError` object
    // content contains the results if no error
}];

FAQ

When should I use the Swift API Client?

If your project is in Swift or partially in Swift, you should use the Swift API Client. We don't support Swift in the Objective-C API Client.

Can I still use the Objective-C API Client?

Yes. If you are using the Objective-C API Client and do not want to upgrade then you can stick to it. We will continue to update and support it.

Clone this wiki locally