IOS Stuff
Revision as of 23:40, 15 February 2019 by PeterHarding (talk | contribs) (Created page with " <pre> func request<T: Codable>(_ request: URLRequest) -> Observable<T> { return Observable<T>.create { observer in // blah blah blah let task = URLSession...")
func request<T: Codable>(_ request: URLRequest) -> Observable<T> { return Observable<T>.create { observer in // blah blah blah let task = URLSession.shared.dataTask(with: request) { (data, response, error) in do { let model: T = try JSONDecoder().decode(T.self, from: data ?? Data()) observer.onNext(model) } catch let error { observer.onError(error) } observer.onCompleted() } task.resume() return Disposables.create { task.cancel() } } }