So I have been updating my code for Swift 3.0 and when the app is opened I sync with iCloud and execute a fetch request.
However I get the optional error for the following
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.syncWithCompletion { (completed) -> Void in
}
Which executes the following function in the appDelegate
func syncWithCompletion(_ completion:@escaping (_ completed:Bool) -> Void) {
if !ensemble.isLeeched {
ensemble.leechPersistentStore { error in
if error != nil {
print("cannot leech \(error!.localizedDescription)")
completion(false)
}
else {
print("leached!!")
completion(true)
}
}
}
else {
ensemble.merge{ error in
if error != nil {
print("cannot merge \(error!.localizedDescription)")
completion(false)
}
else {
print("merged!!")
completion(true)
//NSNotificationCenter.defaultCenter().postNotificationName("Updated-DB", object: nil)
}
}
}
}
I am not sure what the optional error is for, Xcode updated the function header when migrating.
UPDATE:
So apparently the following have a nil value
But I am unsure what is causing this since the Swift 3 migration