RxSwift/RxExample/RxExample/Examples/WikipediaImageSearch/WikipediaAPI/WikipediaPage.swift

36 lines
911 B
Swift

//
// WikipediaPage.swift
// Example
//
// Created by Krunoslav Zaher on 3/28/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
import Foundation
#if !RX_NO_MODULE
import RxSwift
#endif
struct WikipediaPage {
let title: String
let text: String
init(title: String, text: String) {
self.title = title
self.text = text
}
// tedious parsing part
static func parseJSON(_ json: NSDictionary) throws -> WikipediaPage {
guard
let parse = json.value(forKey: "parse"),
let title = (parse as AnyObject).value(forKey: "title") as? String,
let t = (parse as AnyObject).value(forKey: "text"),
let text = (t as AnyObject).value(forKey: "*") as? String else {
throw apiError("Error parsing page content")
}
return WikipediaPage(title: title, text: text)
}
}