I’m building an app with Swift 3.0. So I have this code:
if let cofig = ConfigCoreDataController.shared.loadConfig() {
self.textNumber.text = cofig.numero_centrale
}
If I try to start my application, I have this error:
Fatal error: Unexpectedly found nil while unwrapping an Optional value
the loadConfig method is like this:
func loadConfig() -> Config! {
let request: NSFetchRequest<Config> = NSFetchRequest(entityName: "Config")
request.returnsObjectsAsFaults = false
let urls = self.loadConfigFromFetchRequest(request: request)
if urls.count > 0
{
return urls[0]
}else{
return nil
}
}
now, where is the problem ?