Sunday, 15 January 2012

ios - fatal error: unexpectedly found nil while unwrapping an Optional value while filtering -



ios - fatal error: unexpectedly found nil while unwrapping an Optional value while filtering -

i created tableviewcontroller filter results coredata database , i'm encountering error when effort implement filter next ibaction. i've dug through code checking typos , didn't spot any. assistance in figuring out appreciated, i'm newish programming:

fatal error: unexpectedly found nil while unwrapping optional value @ibaction func savebuttontapped(sender: uibarbuttonitem) { println("savebuttontapped") delegate!.filterviewcontroller(self, didselectpredicate: selectedpredicate, sortdescriptor: selectedsortdescriptor) dismissviewcontrolleranimated(true, completion:nil) }

here's code tvc class:

import uikit import coredata protocol filterviewcontrollerdelegate: class { func filterviewcontroller(filter: rollerfilterviewcontroller, didselectpredicate predicate:nspredicate?, sortdescriptor:nssortdescriptor?) } class rollerfilterviewcontroller: uitableviewcontroller { // outlet connected cell on storyboard @iboutlet weak var shouldercell: uitableviewcell! // variables filter weak var delegate: filterviewcontrollerdelegate? var selectedsortdescriptor: nssortdescriptor? var selectedpredicate: nspredicate? var coredatastack: coredatastack! lazy var shoulderpredicate: nspredicate = { var predicate = nspredicate(format: "stretch.musclegroup contains[cd] %@", "shoulder") homecoming predicate! }() // mark - uitableviewdelegatemethods override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { allow cell = tableview.cellforrowatindexpath(indexpath)! switch cell { // cases muscle groups case shoulderpredicate: selectedpredicate = shoulderpredicate default: println("default case") } if cell.accessorytype == .checkmark { cell.accessorytype = .none println("removed checkmark") } else { cell.accessorytype = .checkmark println("set checkmark") } } // mark - uibutton target action @ibaction func savebuttontapped(sender: uibarbuttonitem) { println("savebuttontapped") delegate!.filterviewcontroller(self, didselectpredicate: selectedpredicate, sortdescriptor: selectedsortdescriptor) dismissviewcontrolleranimated(true, completion:nil) } }

is view controller called or segued view controller? in case, should set delegate property in source's prepareforsegue method, or whatever mechanism invoking current view controller. also, why protocol inheriting "class"? name of protocol?

regardless, delegate nil because it's never beingness set, , seems should set object invoking view controller in question. take note delegate weak, unless object has strong reference it, delegate nil after assigned.

ios uitableview core-data swift

No comments:

Post a Comment