0

In my Database class (all Swift) I have a function called selectFriends.

func selectFriends() -> [Friend] {
    let delegate = UIApplication.shared.delegate as? AppDelegate
    if let context = delegate?.persistentContainer.viewContext {
        let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Friend")
        do {
            return try context.fetch(request) as! [Friend]
        } catch let error {
            print(error)
            return [Friend]()
        }
    }
    else {
        return [Friend]()
    }
}

And when I assign the result to my variable

var friends: [Friend]
friends = database.selectFriends()

I get the error "Failed to call designated initializer on NSManagedObject ". The app works fine but the message appears in console.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Carlo-Rodriguez
  • 158
  • 1
  • 1
  • 8
  • Check [this answer](https://stackoverflow.com/a/33307824/3985749) - somewhere in your code you are initialising an NSManagedObject (or subclass) with the standard init. – pbasdf Nov 01 '17 at 21:01
  • i checked the link and read the post. i found out that i had two functions with NSManagedObjects and the standard init. I am using now optionals like the answer in the link recommend. Thank you – Carlo-Rodriguez Nov 02 '17 at 08:19
  • Possible duplicate of [Resolving 'Failed to call designated initializer on NSManagedObject class'](https://stackoverflow.com/questions/33301250/resolving-failed-to-call-designated-initializer-on-nsmanagedobject-class) – pbasdf Nov 02 '17 at 08:38

0 Answers0