-
Notifications
You must be signed in to change notification settings - Fork 65
Migration guide from Objective C to Swift API Client
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?
- Initialization
- Class name
- Callback conventions
- FAQ
- When should I use the Swift API Client?
- When should I not migrate to the Swift API Client?
- Can I still use the Objective-C 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'
Objective-C API Client
#import "ASAPIClient.h"
ASAPIClient *apiClient = [ASAPIClient apiClientWithApplicationID:@"YourApplicationID" apiKey:@"YourAPIKey"];
Swift API Client
#import "AlgoliaSearch-Swift.h"
Client *apiClient = [[Client alloc] initWithAppID:@"YourApplicationID" apiKey:@"YourAPIKey"];
Objective-C API Client | Swift API Client |
---|---|
ASAPClient | Client |
ASRemoteIndex | Index |
ASQuery | Query |
ASBrowseIterator | BrowseIterator |
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 completionHandler:^(NSDictionary * content, NSError * error) {
// error `nil` or `NSError` object
// content contains the results if no error
}];
If your project is in Swift or partially in Swift, you should use the Swift API Client. We don't support Swift in our Objective-C API Client.
If your project is Objective-C only and you don't plan to use Swift, it is maybe better to continue to use the Objective-C API Client.
Also, you should know that query.queryType
, query.removeWordsIfNoResult
and query.typoTolerance
are not accessible in Objective-C.
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.