Converting our codebase to Swift 3, I have this problem:
ABAddressBookRequestAccessWithCompletion(addressBookRef) { (granted: Bool, error: CFError?) in
        DispatchQueue.main.async {
            if let nsError = error as NSError {
                ...   
            }
        }
}
Compiler error is: 
Cannot convert value of type 'CFError?' to type 'NSError' in coercion
Changing to:
if let nsError = error as? NSError { ... }
Gives the warning: Cast from 'CFError?' to unrelated type 'NSError' always fails
Do not attempt to pass thru NSError at all. Coerce straight to Error, the Swift type.
if let err = error as? Error {
    print(err) // no problem
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With