iOS

To start working with Fleksy Predictive SDK, we first need to sync the required dependency, set required flags, and finally obtain an instance of the PredictiveService class.

To use the SDK, please note that you first need valid license credentials (key and secret) which can be requested in the developer’s dashboard.

Installation

To use Predictive SDK in your app, add the package as a dependency using Swift Package Manager, as follows:

  1. Navigate to Project’s General Pane > Package Dependencies,
  2. Click the + button, enter the repository URL, and click the Add Package button.
https://github.com/FleksySDK/PredictiveSDK-iOS

Supported Platforms

The Predictive SDK supports iOS 13, Mac Catalyst 14 and watchOS 7.

Initialization

The PredictiveService class is the primary way to interact with the Predictive SDK. You need to import PredictiveSDK and create an instance of PredictiveService to start using the autocorrection, next word prediction, and swipe functionalities.

To create a PredictiveService instance, you need to pass it a valid language file (.jet extension) and a LibraryConfiguration object.

Example:

import PredictiveSDK


let languageFile = URL(fileURLWithPath: "resourceArchive-en-US.jet")

let libraryConfiguration = LibraryConfiguration(
    license: LicenseConfiguration(
        licenseKey: "<your-license-key>",
        licenseSecret: "<your-license-secret>"
    )
)

Let’s obtain an instance of PredictiveService:

let predictiveService = try! PredictiveService(languageFileURL: languageFile, configuration: libraryConfiguration)

Now you can start using the methods from the PredictiveService instance.

Methods

There are 3 main methods offered by PredictiveService namely:

There are also additional methods available that can be explored in the class as per requirements.

The currentWordPrediction and nextWordPrediction methods can be used within any application that wishes to take benefit of autocorrection and next word predictions. Both method requires an instance of TypingContext as a parameter.

In case you are integrating the Predictive SDK in your custom keyboard application, you can use additional methods offered by the PredictiveService instance. The swipePrediction and currentWordPrediction (overload method) methods requires an instance of TypingContext and a list of LayoutPoint.

An instance of LayoutPoint contains information regarding the position of the key (within the keyboard) where the user has tapped. The Fleksy Engine uses that to offer better predictions. It is important to note that a valid LayoutType must be provided as a parameter to LibraryConfiguration when instantiating PredictiveService before any methods utilizing LayoutPoint can be used.

Languages

The Predictive SDK supports many languages other than the default starting language. A complete list of supported languages can be found in the Languages section. To work with different languages, the SDK offers various methods in the LanguagesHelper class, among which the two main methods are:

  • availableLanguages that allows you to obtain a list of all supported languages from Fleksy’s remote server, and
  • downloadLanguageFile that can download a given language from Fleksy’s remote server at a given path and invoke a callback function to trigger a custom action.

There are also additional methods available that can be explored in the class as per requirements.

Additional Resources


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on June 18, 2024