Latest 1.1
Homepage https://github.com/igormatyushkin014/SwiftyPredictor
License MIT
Platforms ios 8.0
Authors

SwiftyPredictor

SwiftyPredictor
SwiftyPredictor
SwiftyPredictor
SwiftyPredictor

At a Glance

SwiftyPredictor simplifies work with Yandex.Predictor service in iOS.

How To Get Started

  • Copy content of Source folder to your project.

or

  • Use SwiftyPredictor cocoapod.

Requirements

  • iOS 9.0 and later
  • Xcode 8 and later

Usage

To initialize predictor, simply write something like this:

let predictor = Predictor(APIKey: "some_api_key")

As you noticed, constructor requires API key. If you still don’t have it, obtain new API key here (you’ll need to authorize with Yandex account).

Now you can make requests for text suggestions:

predictor.requestSuggestions(forQuery: "how to ", inLanguage: .english, withLimit: 10) { (suggestions, error) in
    for suggestion in suggestions {
        print(suggestion.text)
    }

    if error != nil {
        print("Error: (error!)")
    }
}

The example above will print suggestions for phrase how to:

  • get
  • make
  • use
  • buy
  • do

You can change language by its identifier or predefined name:

  • .english
  • .russian
  • .custom(identifier: "es") – Spanish language
  • etc.

If you want to receive full list of supported languages, use availableLanguages method:

predictor.availableLanguages { (languages, error) in
    for language in languages {
        print(language.identifier)
    }
}

All asynchronous requests made by Predictor instance are cancellable so you can stop them when it’s needed:

/*
 * Obtain reference to request instance.
 */

let request = predictor.requestSuggestions(forQuery: "how to ", inLanguage: .english, withLimit: 10) { (suggestions, error) in
    // Do something with suggestions here...
}

/*
 * Cancel request when needed.
 */

request.cancel()

License

SwiftyPredictor is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SwiftyPredictor",
    "version": "1.1",
    "summary": "Swift library for Yandex.Predictor service.",
    "description": "This library simplifies work with Yandex.Predictor service in iOS. Written in Swift.",
    "homepage": "https://github.com/igormatyushkin014/SwiftyPredictor",
    "screenshots": "https://github.com/igormatyushkin014/SwiftyPredictor/raw/master/Images/logo_500_500.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Igor Matyushkin": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/igormatyushkin014/SwiftyPredictor.git",
        "tag": "1.1"
    },
    "source_files": [
        "Source",
        "Source/**/*"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This