Trying to use SecCopyErrorMessageString to interpret errorCode. in swift :
var result: OSStatus result = SecItemAdd(query as CFDictionary, nil);
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.
Security
Build Phases > Link Binary With Libraries