Skip to content

Commit

Permalink
quote search issue solve and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjehpark committed Mar 2, 2017
1 parent d91977c commit c2810ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
4 changes: 0 additions & 4 deletions YahooFinance/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Wm9-xU-Cwb" id="D75-Ik-Zi8"/>
<outlet property="delegate" destination="Wm9-xU-Cwb" id="0iL-2U-IqC"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Root View Controller" id="8Wx-ex-Y3X"/>
<connections>
Expand Down
3 changes: 2 additions & 1 deletion YahooFinance/Parsers/QueryParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class QueryParser: Parser {
if let symbolsString = QueryParser.symbolTrayToQueryString(symbolTray) {

// The url is start with http, not https. So you must regist 'http://query.yahooapis.com' 'on 'Info.plist' at 'App Transport Security Settings'
let urlString = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(\(symbolsString))%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json"
let urlString = "http://query.yahooapis.com/v1/public/yql?q=env%20%27store://datatables.org/alltableswithkeys%27%3B%20select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(\(symbolsString))%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json"
// fixed issue by http://stackoverflow.com/questions/31014168/yql-console-no-definition-found-for-table-yahoo-finance-quotes

let responseObjectType = QuoteJSON()

Expand Down
15 changes: 10 additions & 5 deletions YahooFinance/QuoteTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ class QuoteTableViewController: YahooFinanceViewController {

func setQuoteTableView() {
self.quoteTableView.allowsSelection = false
self.quoteTableView.rowHeight = QuoteTableViewCell.expectedHeight
}

func showQuoteTableView() {
let quotes = Variable(self.viewModel.quotes)
quotes.asObservable().bindTo(self.quoteTableView.rx.items(cellIdentifier: QuoteTableViewCell.reuseIdentifier, cellType: QuoteTableViewCell.self)) { (row, element, cell) in
cell.valueLabel.text = String(describing: Array(element.toJSON().values)[row])
cell.keyLabel.text = Array(element.toJSON().keys)[row]
var contents = [(String, Any)]()
for content in self.viewModel.quotes[0].toJSON() {
contents.append(content)
}
let quotesContents = Variable(contents)
quotesContents.asObservable().bindTo(self.quoteTableView.rx.items(cellIdentifier: QuoteTableViewCell.reuseIdentifier, cellType: QuoteTableViewCell.self)) { (row, element, cell) in
cell.keyLabel.text = element.0
cell.valueLabel.text = String(describing: element.1)
}.addDisposableTo(disposeBag)
}
}
Expand Down
16 changes: 5 additions & 11 deletions YahooFinance/SymbolTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ class SymbolTableViewController: YahooFinanceViewController {
self.viewModel = self
self.navigationItem.title = self.viewModel.getTexts(.title)

self.setSymbolViewModel()
self.showSymbolViewModel()
self.setSymbolTableView()
self.showSymbolTableView()
}

func setSymbolViewModel() {
func setSymbolTableView() {
self.symbolTableView.rx.modelSelected(Result.self).subscribe { (event:Event<Result>) in
if let symbol = event.element?.symbol {
self.viewModel.queryQuote(symbol)
}
}.addDisposableTo(disposeBag)
}

func showSymbolViewModel() {
func showSymbolTableView() {
let results = Variable(self.viewModel.results)
results.asObservable().bindTo(self.symbolTableView.rx.items(cellIdentifier: SymbolTableViewCell.reuseIdentifier, cellType: SymbolTableViewCell.self)) { (row, element, cell) in
cell.nameLabel.text = (element.name ?? "")
Expand All @@ -47,7 +47,7 @@ class SymbolTableViewController: YahooFinanceViewController {
extension SymbolTableViewController: SymbolViewModel {

func refreshUI() {
self.showSymbolViewModel()
self.showSymbolTableView()
}

func showLoading() {
Expand All @@ -69,11 +69,5 @@ extension SymbolTableViewController: SymbolViewModel {

})
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let symbol = self.viewModel.results[indexPath.row].symbol {
self.viewModel.queryQuote(symbol)
}
}

}

0 comments on commit c2810ce

Please sign in to comment.