objcio / core-data

Sample code for the objc.io Core Data book
https://www.objc.io/books/core-data
MIT License
770 stars 198 forks source link

Crash when instantiating FetchedResultsDataProvider #19

Closed lucatorella closed 7 years ago

lucatorella commented 8 years ago

I was trying the code to use Core Data and Table Views, and I get a crash just in iOS 7:

#0
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x00000000004266e0

Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x6dbd22 swift_initClassMetadata_UniversalStrategy + 439
1  MyApp                          0xab284 protocol witness table accessor for <A where ...> FetchedResultsDataProvider<A> (FetchedResultsDataProvider.swift)
2  libswiftCore.dylib             0x6dcdbf swift_getGenericWitnessTable + 888
3  libswiftCore.dylib             0x6dccb5 swift_getGenericWitnessTable + 622
4  libswiftCore.dylib             0x6daee7 swift_getResilientMetadata + 382
5  libswiftCore.dylib             0x6db03f swift_getGenericMetadata3 + 68

My table view controller code looks like this:

private func setupTableView() {
   tableView.registerNib(UINib(nibName: "Cell", bundle: nil), forCellReuseIdentifier: "Cell")

   let request = Event.sortedFetchRequest
   request.fetchBatchSize = 20
   request.returnsObjectsAsFaults = false

   let frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
   let dataProvider = FetchedResultsDataProvider(fetchedResultsController: frc, delegate: self)
   dataSource = TableViewDataSource(tableView: tableView, dataProvider: dataProvider, delegate: self)
}
lucatorella commented 8 years ago

I think it's a compiler issue, since it crashes when compiled with Swift 2.2.1, but not when compiled with Swift 2.1