Created
January 16, 2016 04:14
-
-
Save jasminsuljic/56a56c980d390802a144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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