これは私が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
私はこの質問を読んだが、解決策は何か実際には?さらに、** Objective-C ** lanagugeがあり、ここに** Swift **があります。 –
あなたは 'try! 'を使っています。それはうまくいかなかったので、* try catch blocks *を使ってみてください。そのため、アプリケーションはクラッシュすることはありませんが、より詳細な例外がスローされます。 – Binarian