1

On compile this code:

func managedObjectContext_roster() -> NSManagedObjectContext {
    return Messenger.sharedInstance.xmppRosterStorage!.mainThreadManagedObjectContext
}

I get the next error:

CoreData: error: Failed to call designated initializer on NSManagedObject class 'XMPPUserCoreDataStorageObject'

What this error means and how can I fix it? I searched in Google, but did not find anything

UPDATE

func fetchedResultsController() -> NSFetchedResultsController? {
    if fetchedResultsControllerVar == nil {
        let moc = MessengerRoster.sharedInstance.managedObjectContext_roster() as NSManagedObjectContext?
        let entity = NSEntityDescription.entityForName("XMPPUserCoreDataStorageObject", inManagedObjectContext: moc!)
        let sd1 = NSSortDescriptor(key: "sectionNum", ascending: true)
        let sd2 = NSSortDescriptor(key: "displayName", ascending: true)

        let sortDescriptors = [sd1, sd2]
        let fetchRequest = NSFetchRequest()

        fetchRequest.entity = entity
        fetchRequest.sortDescriptors = sortDescriptors
        fetchRequest.fetchBatchSize = 10

        fetchedResultsControllerVar = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: moc!, sectionNameKeyPath: "sectionNum", cacheName: nil)
        fetchedResultsControllerVar?.delegate = self

        if fetchedResultsControllerVar?.performFetch(nil) == nil {
            //Handle fetch error
        }
    }

    return fetchedResultsControllerVar!
}
  • 1
    A quick search on Google reveals [this](http://stackoverflow.com/q/14671478/335858) as the first link. It's not Swift, but there is no difference apart from the syntax. – Sergey Kalinichenko Sep 04 '15 at 12:08
  • @dasblinkenlight and how can I fix it? Can you help me please, I do not know ObjC at all –  Sep 04 '15 at 12:11
  • That error says you tried to create an `XMPPUserCoreDataStorageObject` but you did not call the designated initializer. Calling designated initializers is required in Swift, whether or not you're using Core Data. None of the code you have posted creates an `XMPPUserCoreDataStorageObject`, so it's impossible to say what you would need to change. – Tom Harrington Sep 04 '15 at 18:15

0 Answers0