Group Group Group Group Group Group Group Group Group

Chapter 6 - Testing Sequential Migrations

#1

I’m trying to test sequential migrations and the migrations appear to work, but the app is giving me a warning Multiple NSEntityDescriptions claim the NSManagedObject subclass ‘UnCloudNotes.Note’ so +entity is unable to disambiguate.

The app then crashes when it tries to set up the fetched results controller in NotesListViewController (the sort descriptor is not set up as a result of the above warning):

fileprivate lazy var notes: NSFetchedResultsController = {
let context = self.stack.managedContext
let request = Note.fetchRequest() as! NSFetchRequest
request.sortDescriptors = [NSSortDescriptor(key: #keyPath(Note.dateCreated), ascending: false)]

let notes = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
notes.delegate = self
return notes

}()

I’ve followed everything line by line so I don’t know why this error is appearing.

#2

Assuming you didn’t create two Note.swift classes, you may have the CodeGen setting for Note in the entity designer set to create a class. It should be set to None. It sounds like it is creating a Note class, which will be hidden, and that generated class is in conflict with the Note.swift class you already have.

#3

The CodeGen setting for Note is set to Manual/None.

However, when I changed the fetch request in NotesListViewController from

let request = Note.fetchRequest() as! NSFetchRequest<Note>

to

let request: NSFetchRequest<Note> = NSFetchRequest(entityName: “Note”)

all works fine. Problem solved.

2 Likes
#4

I faced the same problem. I applied your solution and problem solved as well.

closed #5

This topic was automatically closed after 166 days. New replies are no longer allowed.