swift - API to table view, adding numeric values and adding columns, and refreshing table every 10 seconds -


so, have been trying data api, of stock market, want refreshed every 10-15 seconds. api "https://bittrex.com/api/v1.1/public/getmarketsummaries". have name being displayed, when have display "last" decimal, not able display here:

override func tableview(_ tableview: uitableview, cellforrowat indexpath:  indexpath) -> uitableviewcell {  let cell = tableview.dequeuereusablecell(withidentifier: "cell", for:indexpath)      let item = self.listdata[indexpath.row]     cell.textlabel?.text = item["marketname"] as? string     cell.detailtextlabel?.text = item["last"] as? string     print(self.listdata.count)      return cell } 
  1. i want add column displays "high", "low", api.
  2. i want refresh every 10-15 seconds.

i want more on project. chemical engineer, wanted implement idea , started coding myself. grateful if contact me on e-mail(siddhantmehandru@gmail.com). ready compensate work :)

btw, here full code:

import uikit var listdata = [[string : anyobject]]()  class demojsontableviewcontroller: uitableviewcontroller {  var listdata = [[string : anyobject]]()  override func viewdidload() {     super.viewdidload()      let url:string = "https://bittrex.com/api/v1.1/public/getmarketsummaries"      let urlrequest = url(string: url)      urlsession.shared.datatask(with: urlrequest!) { (data, response, error) in         if(error != nil){             print(error.debugdescription)         }         else{             do{                 var response = try jsonserialization.jsonobject(with: data!, options: .allowfragments) as! [string:anyobject]                 self.listdata = response["result"] as! [[string:anyobject]]                 dispatchqueue.main.async {                     self.tableview.reloaddata()                 }             }catch let error nserror{                 print(error)             }         }         }.resume()     // uncomment following line preserve selection between presentations     // self.clearsselectiononviewwillappear = false      // uncomment following line display edit button in navigation bar view controller.     // self.navigationitem.rightbarbuttonitem = self.editbuttonitem() }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  // mark: - table view data source  override func numberofsections(in tableview: uitableview) -> int {     // #warning incomplete implementation, return number of sections     return 1 }  override func tableview(_ tableview: uitableview, numberofrowsinsection section: int) -> int {     // #warning incomplete implementation, return number of rows     return self.listdata.count }   override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)     let item = self.listdata[indexpath.row]     cell.textlabel?.text = item["marketname"] as? string     cell.detailtextlabel?.text = item["last"] as? string     print(self.listdata.count)      return cell } } 

thanks!

try this:

override func tableview(_ tableview: uitableview, cellforrowat indexpath:  indexpath) -> uitableviewcell {  let cell = tableview.dequeuereusablecell(withidentifier: "cell", for:indexpath)      let item = self.listdata[indexpath.row]     cell.textlabel?.text = item["marketname"] as? string     let lastvalue = item["last"] as? nsnumber     cell.detailtextlabel?.text = lastvalue?.stringvalue     print(self.listdata.count)      return cell }  override func viewdidload() {     super.viewdidload()     timer = timer.scheduledtimer(timeinterval: 10, target: self,   selector: (#selector(self.sendupdaterequest)), userinfo: nil, repeats: true) } 

function call repeatedly after each 10 sec.

func sendupdaterequest()     {     let url:string = "https://bittrex.com/api/v1.1/public/getmarketsummaries"      let urlrequest = url(string: url)      urlsession.shared.datatask(with: urlrequest!) { (data, response, error) in         if(error != nil){             print(error.debugdescription)         }         else{             do{                 var response = try jsonserialization.jsonobject(with: data!, options: .allowfragments) as! [string:anyobject]                 self.listdata = response["result"] as! [[string:anyobject]]                 dispatchqueue.main.async {                     self.tableview.reloaddata()                 }             }catch let error nserror{                 print(error)             }         }         }.resume()     } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -