When setting up a CoreData stack, I noticed that NSPersistenceContainer may return "nil" if the name of the model is spelled wrong.
...
let container = NSPersistentContainer(name: name)
guard container != nil else { // warning here ... see explanation below
promise(.failure(.objectModelNotFound))
return
}
In the code fragment above (which is part of utility function) the compiler complains about the guard statement with a warning: "Comparing non-optional value of type 'NSPersistentContainer' to 'nil' always returns true".
The init for the NSPersistenceContainer is declared as:
convenience init(name: String)
To summarise: If the name of the model is wrong, the code in the guard's else statement is reached, and a message in the console window says: "CoreData: error: Failed to load model named XYZ"
The question then is, is it okay for NSPersistentContainer to do so? Or maybe it was stated incorrectly in the documentation?
And if not, what is the correct way to handle the situation in code without getting a warning?