Trying to use SecCopyErrorMessageString to interpret errorCode. in swift :
var result: OSStatus
result = SecItemAdd(query as CFDictionary, nil);
The SecCopyErrorMessageString
function only became available on iOS in version 11.3. Prior to that, it could only be used on OS X.
It may not be obvious: This API is part of the Security
framework. You need to add the framework to your project target's Build Phases > Link Binary With Libraries
.
The above answer is a bit outdated, according to Apple, iOS 11.3, tvOS 11.3 and watchOS 4.3 started to support this since the beta version of SDK.
You'd need to compile against those supported SDKs to use that function. Otherwise, only macOS support that for now.