I am getting more than a little sick of this iPhone SDK and its documentation...
I am calling AudioConverterNew
in the documentation under Returns: it says \
For iOS 11.3+, I'm using an extension on OSStatus…
extension OSStatus {
var error: NSError? {
guard self != errSecSuccess else { return nil }
let message = SecCopyErrorMessageString(self, nil) as String? ?? "Unknown error"
return NSError(domain: NSOSStatusErrorDomain, code: Int(self), userInfo: [
NSLocalizedDescriptionKey: message])
}
}
which you can call like…
let status = SecItemAdd(attributes as CFDictionary, nil)
if let error = status.error {
throw error
}
// etc
Having written this I noticed this is very close to @RomanMykitchak's earlier answer (so please give him the upvote) - but I'll leave it here as the extension might prove useful to someone.