ios - Notification center today widget flashes and then "unable to load" Swift -


i developing simple reminders app , i've run trouble today extension. extension works on ipad , in simulator, on iphone flashes twice before displaying "unable load" message. believe caused sort of memory problem, didrecievememorywarning called in 1 of debug sessions, console output receive "program ended exit code: 0." appreciated. here code today extension:

import uikit import notificationcenter  class todayviewcontroller: uitableviewcontroller, ncwidgetproviding { let repeattitles = ["no repeat", "repeat every minute", "repeat hourly", "repeat daily", "repeat weekly", "repeat monthly", "repeat annually", "repeat monthly week number", "repeat annual week number"] var maincolor = uicolor(colorliteralred: 57/255, green: 181/255, blue: 74/255, alpha: 1.0) var secondcolor = uicolor(colorliteralred: 95/255, green: 147/255, blue: 196/255, alpha: 1.0)  var objects = [nsarray]() override func viewdidload() {     super.viewdidload()      }   override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated.     print("memory warning nc")  }   override func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return objects.count }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath)      let object = objects[indexpath.row] nsarray     if object[7] as! string == "createone" || object[7] as! string == "morememos" {         cell.detailtextlabel!.text = object[2] as? string         cell.detailtextlabel!.textcolor = secondcolor         cell.detailtextlabel!.font = uifont.systemfontofsize(16)     }     else {         cell.textlabel!.text = object[2] as? string         if let thedatetostore = object[4] as? nsdate {             if object[6] as! bool == true {                 if (object[3] as! string).stringbytrimmingcharactersinset(nscharacterset.whitespaceandnewlinecharacterset()) == "" {                     cell.detailtextlabel!.text = "memo muted"                 }                 else {                     cell.detailtextlabel!.text = "memo muted- \(object[3] as! string)"                 }             }             else {                 let timestamp = nsdateformatter.localizedstringfromdate(thedatetostore, datestyle: .shortstyle, timestyle: .shortstyle)                 let repeattitle = repeattitles[(object[5] as? int)!]                 if (object[3] as! string).stringbytrimmingcharactersinset(nscharacterset.whitespaceandnewlinecharacterset()) == "" {                     cell.detailtextlabel!.text = "\(timestamp): \(repeattitle)"                 }                 else {                     cell.detailtextlabel!.text = "\(timestamp): \(repeattitle)- \(object[3] as! string)"                 }             }         }         else {             if (object[3] as! string).stringbytrimmingcharactersinset(nscharacterset.whitespaceandnewlinecharacterset()) == "" {                 cell.detailtextlabel!.text = "memo muted"             }             else {                 cell.detailtextlabel!.text = "memo muted- \(object[3] as! string)"             }         }         cell.textlabel!.textcolor = maincolor         cell.detailtextlabel!.textcolor = uicolor.whitecolor()     }     return cell } func updatewithchanges(){     var newobjects = nsuserdefaults(suitename: "group.me.memosapp")!.objectforkey("cashedmemos") as? [nsarray]     if newobjects == nil {         newobjects = [nsarray]()     }     else {         if newobjects!.count > 5 {             in stride(from: newobjects!.count - 1, through: 5, by: -1) {                 newobjects!.removeatindex(i)             }             newobjects!.append([0, true, "more memos", "", "", 0, false, "morememos"])         }     }     newobjects!.append([0, true, "create new memo", "", "", 0, false, "createone"])     objects = newobjects!     newobjects = nil     tableview.reloaddata()     updatepreferredcontentsize() }  override func viewwillappear(animated: bool) {     updatewithchanges() } override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {     if let object = objects[indexpath.row] nsarray? {         if object[7] as! string == "createone" {             self.extensioncontext?.openurl(nsurl(string: "memosapp://creatememo")!, completionhandler: nil)         }         else if object[7] as! string == "morememos" {             self.extensioncontext?.openurl(nsurl(string: "memosapp://morememosfromnc")!, completionhandler: nil)         }         else {             let idnum = object[0] as! int             let deviceid = object[7] as! string             let memoid = "m\(idnum)\(deviceid)"             self.extensioncontext?.openurl(nsurl(string: "memosapp://openmemo?\(memoid)")!, completionhandler: nil)         }     }     tableview.deselectrowatindexpath(indexpath, animated: true) }  func widgetperformupdatewithcompletionhandler(completionhandler: ((ncupdateresult) -> void)) {     completionhandler(ncupdateresult.nodata) } func widgetmargininsetsforproposedmargininsets     (defaultmargininsets: uiedgeinsets) -> (uiedgeinsets) {         return uiedgeinsetszero } func updatepreferredcontentsize() {     preferredcontentsize = cgsizemake(cgfloat(0), cgfloat((objects.count * 50) - 1))//+ tableview.sectionfooterheight) } } 

the today extension loads cashed array of memos object in nsuserdefaults shared group. code written in swift 2.0.

it turned out had created uilabel in base cell tableview (used make cell clickable despite having transparent background in nc) , long length of label causing widget use memory.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -