The Swift SDK provides a convenient API for your iOS and OS X application to record your users’ behaviors in the event server and retrieve predictions from PredictionIO engines.
Requirements
iOS 7.0+ or OS X 10.9+
Xcode 6.1
Installation
Cocoapods
Only CocoaPods 0.36.0 beta (and rc1) supports Swift and embedded frameworks. So CocoaPods needs to be installed with the following command.
$ gem install cocoapods --pre
Add the following lines to your Podfile.
# platform must be at least iOS 8.0 to use dynamic frameworks
platform :ios, '8.0'
use_frameworks!
pod 'PredictionIOSDK', :git => 'https://github.com/minhtule/PredictionIO-Swift-SDK.git'
Then run the following command.
$ pod install
Finally, import the SDK in your Swift files before using.
import PredictionIOSDK
Manually
You can just drag two files: PredictionIOSDK.swift and Alamofire.swift into your project.
Note that Alamofire.swift has been slightly modified from the original; however, if you have already integrated the original Alamofire.swift file to your project, you don’t need to include Alamofire.swift from this repo again.
Usage
EngineClient
Use EngineClient to query predictions from the PredictionIO Engines.
let engineClient = EngineClient(baseURL: "http://localhost:8000")
let query = [
"user": 1,
"num": 2
]
engineClient.sendQuery(query) { (request, response, JSON, error) in
if let data = JSON as? [String: [[String: AnyObject]]] {
...
}
...
}
EventClient
Use EventClient to send information to the PredictionIO Event Server.
Please follow this quick guide to start the Event Server and set up a Recommendation Engine on your local machine first.
You also need to:
Include your app’s access key in DataCollectorViewController.swift.
Import some data using the python script as instructed in step 4b. Alternatively, you can use the demo app to record new rating events; however, remember to re-train and deploy the engine before querying for recommendations.
Run the iPhone or iPad simulator!
There are 2 screens in the demo app:
Data Collector: corresponding to step 4a. Collecting Data in the quick guide.
Item Recommendation: corresponding to step 6. Use the Engine in the quick guide.
License
PredictionIO Swift SDK is released under the Apache License 2.0. Please see
LICENSE for details.
PredictionIO Swift SDK
[
]
(https://travis-ci.org/minhtule/PredictionIO-Swift-SDK)
The Swift SDK provides a convenient API for your iOS and OS X application to record your users’ behaviors in the event server and retrieve predictions from PredictionIO engines.
Requirements
Installation
Cocoapods
Only CocoaPods 0.36.0 beta (and rc1) supports Swift and embedded frameworks. So CocoaPods needs to be installed with the following command.
Add the following lines to your
Podfile.Then run the following command.
Finally, import the SDK in your Swift files before using.
Manually
You can just drag two files:
PredictionIOSDK.swiftandAlamofire.swiftinto your project.Note that
Alamofire.swifthas been slightly modified from the original; however, if you have already integrated the originalAlamofire.swiftfile to your project, you don’t need to includeAlamofire.swiftfrom this repo again.Usage
EngineClient
Use
EngineClientto query predictions from the PredictionIO Engines.EventClient
Use
EventClientto send information to the PredictionIO Event Server.There are other convenient methods to modify user’s or item’s properties. Please see the API documentation for more details.
Documentation
The latest API documentation is available at http://minhtule.github.io/PredictionIO-Swift-SDK/index.html.
iOS Demo App
Please follow this quick guide to start the Event Server and set up a Recommendation Engine on your local machine first.
You also need to:
DataCollectorViewController.swift.There are 2 screens in the demo app:
License
PredictionIO Swift SDK is released under the Apache License 2.0. Please see LICENSE for details.