swift - Use of Unresolved Identifier Error Code -
i wondering why keep getting error message, use of unresolved identifier 'changeinpercent'. not sure why keep getting error message help, appreciate it.
here code.
import uikit class stockstableviewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate { //1 private var stocks: [(string,double)] = [("aapl",+1.5),("fb",+2.33),("goog",-4.3)] @iboutlet weak var tableview: uitableview! override func viewdidload() { super.viewdidload() //2 nsnotificationcenter.defaultcenter().addobserver(self, selector: "stocksupdated:", name: knotificationstocksupdated, object: nil) self.updatestocks() } override func didreceivememorywarning() { super.didreceivememorywarning() } //uitableviewdatasource func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return stocks.count } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell:uitableviewcell = uitableviewcell(style: uitableviewcellstyle.value1, reuseidentifier: "cellid") cell.textlabel!.text = stocks[indexpath.row].0 //position 0 of tuple: symbol "aapl" cell.detailtextlabel!.text = "\(stocks[indexpath.row].1)" + "%" //position 1 of tuple: value "1.5" string return cell } //uitableviewdelegate func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { } //customize cell func tableview(tableview: uitableview, willdisplaycell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) { switch stocks[indexpath.row].1 { case let x x < 0.0: cell.backgroundcolor = uicolor(red: 255.0/255.0, green: 59.0/255.0, blue: 48.0/255.0, alpha: 1.0) case let x x > 0.0: cell.backgroundcolor = uicolor(red: 76.0/255.0, green: 217.0/255.0, blue: 100.0/255.0, alpha: 1.0) case _: cell.backgroundcolor = uicolor(red: 44.0/255.0, green: 186.0/255.0, blue: 231.0/255.0, alpha: 1.0) } cell.textlabel!.textcolor = uicolor.whitecolor() cell.detailtextlabel!.textcolor = uicolor.whitecolor() cell.textlabel!.font = uifont(name: "helveticaneue-condensedbold", size: 48) cell.detailtextlabel!.font = uifont(name: "helveticaneue-condensedbold", size: 48) cell.textlabel!.shadowcolor = uicolor(red: 0, green: 0, blue: 0, alpha: 0.25) cell.textlabel!.shadowoffset = cgsize(width: 0, height: 1) cell.detailtextlabel!.shadowcolor = uicolor(red: 0, green: 0, blue: 0, alpha: 0.25) cell.detailtextlabel!.shadowoffset = cgsize(width: 0, height: 1) } //customize height of cell func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { return 120 } //stock updates //3 func updatestocks() { let stockmanager:stockmanagersingleton = stockmanagersingleton.sharedinstance stockmanager.updatelistofsymbols(stocks) //repeat method after 15 secs. (for simplicity of tutorial not cancelling never) dispatch_after( dispatch_time( dispatch_time_now, int64(15 * double(nsec_per_sec)) ), dispatch_get_main_queue(), { self.updatestocks() } ) } //4 func stocksupdated(notification: nsnotification) { let values = (notification.userinfo as! dictionary<string,nsarray>) let stocksreceived:nsarray = values[knotificationstocksupdated]! stocks.removeall(keepcapacity: false) quote in stocksreceived { let quotedict:nsdictionary = quote as! nsdictionary var changeinpercentstring = quotedict["changeinpercent"] as! string let changeinpercentstringclean: nsstring = (changeinpercentstring nsstring).substringtoindex(changeinpercent(changeinpercentstring)-1) stocks.append(quotedict["symbol"] as! string,changeinpercentstringclean.doublevalue) } tableview.reloaddata() nslog("symbols values updated :)") } }
the line of code error is,
var changeinpercentstring = quotedict["changeinpercent"] as! string
var changeinpercentstring = quotedict["changeinpercent"] as! string let changeinpercentstringclean: nsstring = (changeinpercentstring nsstring).substringtoindex((changeinpercentstring nsstring).length-1)
Comments
Post a Comment