Skip to content

Instantly share code, notes, and snippets.

@jasminsuljic
Created January 16, 2016 04:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasminsuljic/56a56c980d390802a144 to your computer and use it in GitHub Desktop.
Save jasminsuljic/56a56c980d390802a144 to your computer and use it in GitHub Desktop.
import Foundation
import RxSwift
import ObjectMapper
import AlamofireObjectMapper
class User:Mappable{
var username: String?
var age: Int?
required init?(_ map: Map){
mapping(map);
}
func mapping(map: Map) {
username <- map["username"];
age <- map["age"];
}
}
final class ObjectResponse<T:Mappable>:Mappable{
var data:T?;
init?(_ map:Map){
mapping(map);
}
func mapping(map:Map){
data <- map["data"];
}
}
class Test{
func run(){
let apiUrl = "";//prefered api url
//Example is with connectable, regular observable can be used, just omit publish method call
let connectable: ConnectableObservable<ObjectResponse<User>> = JSON(Alamofire.Method.POST,apiUrl
.observeOn(MainScheduler.instance)
.publish();
_ = connectable.subscribe(onNext: {r in
debugPrint(r.data);
});
return connectable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment