Adds one or more items to a keychain.
- iOS 2.0+
- macOS 10.6+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
A dictionary that describes the item to add. A typical
attributesdictionary consists of:
The item's class. Different attributes and behaviors apply to different classes of items. You use the
kkey with a suitable value to tell keychain services whether the data you want to store represents a password, a certificate, a cryptographic key, or something else. See Item Class Keys and Values.
The data. Use the
kkey to indicate the data you want to store. Keychain services takes care of encrypting this data if the item is secret, namely when it’s one of the password types or involves a private key.
Sec Value Data
Optional attributes. Include attribute keys that allow you to find the item later and that indicate how the data should be used or shared. You may add any number of attributes, although many are specific to a particular class of item. See Item Attribute Keys and Values for the complete list.
Optional return types. Include one or more return type keys to indicate what data, if any, you want returned upon successful completion. You often ignore the return data from a
Seccall, in which case no return value key is needed. See Item Return Result Keys for more information.
On return, a reference to the newly added items. The exact type of the result is based on the values supplied in
attributes, as discussed in Item Return Result Keys. Pass
nilif you don’t need the result. Otherwise, your app becomes responsible for releasing the referenced object.
A result code. See Security Framework Result Codes.
To add multiple items to a keychain at once use the
k key in the
attributes dictionary with an array of dictionaries (each corresponding to one of the items) as its value. This is only supported for non-password items.
When you use Xcode to create an application, Xcode adds an
application-identifier entitlement to the application bundle. Keychain Services uses this entitlement to grant the application access to its own keychain items. If you want the new keychain item to be shared among multiple applications, include the
k key in the
attributes dictionary. The value of this key must be the name of a keychain access group to which all of the programs that will share this item belong.