From c2810cedfa1805f4849988dd7b48d52c4a3cd328 Mon Sep 17 00:00:00 2001 From: yangjehpark Date: Thu, 2 Mar 2017 15:52:53 +0900 Subject: [PATCH] quote search issue solve and renaming --- YahooFinance/Base.lproj/Main.storyboard | 4 ---- YahooFinance/Parsers/QueryParser.swift | 3 ++- YahooFinance/QuoteTableViewController.swift | 15 ++++++++++----- YahooFinance/SymbolTableViewController.swift | 16 +++++----------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/YahooFinance/Base.lproj/Main.storyboard b/YahooFinance/Base.lproj/Main.storyboard index 15a5c94..36609ab 100644 --- a/YahooFinance/Base.lproj/Main.storyboard +++ b/YahooFinance/Base.lproj/Main.storyboard @@ -175,10 +175,6 @@ - - - - diff --git a/YahooFinance/Parsers/QueryParser.swift b/YahooFinance/Parsers/QueryParser.swift index b8d749c..bad0f13 100644 --- a/YahooFinance/Parsers/QueryParser.swift +++ b/YahooFinance/Parsers/QueryParser.swift @@ -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() diff --git a/YahooFinance/QuoteTableViewController.swift b/YahooFinance/QuoteTableViewController.swift index fc36bac..fd07402 100644 --- a/YahooFinance/QuoteTableViewController.swift +++ b/YahooFinance/QuoteTableViewController.swift @@ -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) } } diff --git a/YahooFinance/SymbolTableViewController.swift b/YahooFinance/SymbolTableViewController.swift index 668ff42..25684ee 100644 --- a/YahooFinance/SymbolTableViewController.swift +++ b/YahooFinance/SymbolTableViewController.swift @@ -22,11 +22,11 @@ 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) in if let symbol = event.element?.symbol { self.viewModel.queryQuote(symbol) @@ -34,7 +34,7 @@ class SymbolTableViewController: YahooFinanceViewController { }.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 ?? "") @@ -47,7 +47,7 @@ class SymbolTableViewController: YahooFinanceViewController { extension SymbolTableViewController: SymbolViewModel { func refreshUI() { - self.showSymbolViewModel() + self.showSymbolTableView() } func showLoading() { @@ -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) - } - } }