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 Predictive SDK in your app, add the package as a dependency using Swift Package Manager, as follows:
+
button, enter the repository URL, and click the Add Package button.https://github.com/FleksySDK/PredictiveSDK-iOS
The Predictive SDK supports iOS 13
, Mac Catalyst 14
and watchOS 7
.
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.
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.
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:
There are also additional methods available that can be explored in the class as per requirements.