В моем контроллере у меня есть дваUICollectionView
«S с двумя разными NSFetchedResultsControllers
:Swift: NSArrayM controllerWillChangeContent]: непризнанный селектор направлен например
Это, как я создаю его в viewDidLoad:
:
private func setupFetchedResultsControllers() {
let currentStudent = BWSettings.sharedSettings.currentUser as! BWCoreDataStudent
let context = NSManagedObjectContext.MR_defaultContext()
let topFetchReguest = NSFetchRequest(entityName: "BWCoreDataWishlistBook")
let positionDescriptor = NSSortDescriptor(key: "position", ascending: true)
topFetchReguest.sortDescriptors = [positionDescriptor]
topFetchedResultsController = NSFetchedResultsController(fetchRequest: topFetchReguest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
topFetchedResultsController.fetchRequest.predicate = NSPredicate(format: "student.id = %lld AND position != nil", currentStudent.id)
topFetchedResultsController.delegate = BWStudentWishlistFetchedResultsControllerDelegate(collectionView: topCollectionView, studentWishlistContainerViewController: self)
try! topFetchedResultsController.performFetch()
let bottomFetchReguest = NSFetchRequest(entityName: "BWCoreDataWishlistBook")
let addedAtDescriptor = NSSortDescriptor(key: "createdAt", ascending: true)
bottomFetchReguest.sortDescriptors = [addedAtDescriptor]
bottomFetchedResultsController = NSFetchedResultsController(fetchRequest: bottomFetchReguest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
bottomFetchedResultsController.fetchRequest.predicate = NSPredicate(format: "student.id = %lld AND position = nil", currentStudent.id)
bottomFetchedResultsController.delegate = BWStudentWishlistFetchedResultsControllerDelegate(collectionView: bottomCollectionView, studentWishlistContainerViewController: self)
try! bottomFetchedResultsController.performFetch()
}
И это мой пользовательский делегат:
class BWStudentWishlistFetchedResultsControllerDelegate: NSObject, NSFetchedResultsControllerDelegate {
private var collectionView: UICollectionView!
private var collectionViewChanges = [[NSFetchedResultsChangeType: [NSIndexPath]]]()
private weak var studentWishlistContainerViewController: BWStudentWishlistContainerViewController!
init(collectionView: UICollectionView, studentWishlistContainerViewController: BWStudentWishlistContainerViewController) {
self.collectionView = collectionView
self.studentWishlistContainerViewController = studentWishlistContainerViewController
}
//MARK: - NSFetchedResultsControllerDelegate
//here are my custom default methods
}
Это сообщение вся ошибка:
*** Нагрузочный приложение из-за неперехваченного исключением 'NSInvalidArgumentException', причина: '- [__ NSArrayM controllerWillChangeContent]: непризнанные селектор направил к экземпляру 0x14ec0d930'
Почему это происходит?
http://stackoverflow.com/questions/3532861/core-data-app-crashing-with-controllerwillchangecontent-unrecognized-selector?rq=1 – Rajesh
Я прочитал этот вопрос, но что такое solutio n на самом деле? Кроме того, есть ** Objective-C ** lanaguge, и здесь ** Swift **. –
Вы используете 'try!'. Так как это не сработало, попробуйте использовать * try catch blocks *, поэтому приложение не будет разбиваться, а генерирует исключение, которое имеет более подробную информацию. – Binarian