The sample project CloudKitShare downloaded from developer.apple.com Sharing CloudKit Data with Other iCloud Users has a line of code in HandleCloudKitError.swift that optionally casts an instance of Error to a variable of type NSError.
guard let nsError = error as NSError? else {
return nil
}
Under what conditions would this fail? I thought this would always succeed.
How do I find out why the cast is unsuccessful? When I put code that prints the type of variable 'error', it seems to always result in Optional like so:
Code:
guard let nsError = error as NSError? else {
print(type(of: error))
return nil
}
Optional