ios - NSFetchedResultsController -[__NSArrayM insertObject:atIndex:]: object cannot be nil -
i've done quite bit of research on issue, found nothing lead me solution. attempting use nsfetchedresultscontroller
, , getting error when run app:
* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[__nsarraym insertobject:atindex:]: object cannot nil' *** first throw call stack:
i have found people encountered problem when using estimatedheightforrowatindexpath
method, i'm not using it.
using exception breakpoint revealed it's crashing @ line in below block of code: let frc = nsfetchedresultscontroller(fetchrequest: fetchrequest, managedobjectcontext: self.managedcontext, sectionnamekeypath: "date.thedate", cachename: nil)
. doesn't make past here.
i have print statement below never executes. managedobjectcontext exist. frc
called first time in viewdidload (code below). i'll include appdelegate code.
thanks in advance!
here's relevant code:
import uikit import coredata class transactionsviewcontroller: uiviewcontroller, uitableviewdatasource, nsfetchedresultscontrollerdelegate { var containerdelegate: containerdelegate? var managedcontext: nsmanagedobjectcontext! lazy var frc: nsfetchedresultscontroller = { // initialize fetch request let fetchrequest = nsfetchrequest(entityname: "dailytransactions") // initialize fetched results controller let frc = nsfetchedresultscontroller(fetchrequest: fetchrequest, managedobjectcontext: self.managedcontext, sectionnamekeypath: "date.thedate", cachename: nil) print("assigned frc complete.") // configure fetched results controller frc.delegate = self print("frc finished") return frc }()
frc
first used in viewdidload this:
// exectue fetch request { try self.frc.performfetch() } catch { let fetcherror = error nserror print("\(fetcherror), \(fetcherror.userinfo)") }
update:
after using sort descriptions on fetch request , changed section key path nil, resolved issue. can change section key path date.thedate
, run fine.
your managed context zero. therefore don't anything. why not initialized, there should context , otherwise objects can't propagated...
Comments
Post a Comment