Sets a data object for the specified key in the key-value store.
- iOS 5.0+
- macOS 10.7+
- Mac Catalyst 13.0+
- tvOS 9.0+
The data object to store. The total size of this data object (including any object overhead) must not exceed 1 MB.
The key under which to store the value. The length of this key must not exceed 64 bytes using UTF8 encoding.
NSData object as a value in key-value storage lets you store arbitrary data. For example, in a game app, you can use it to store game state to iCloud.
Be sure to exercise caution when storing a data object. Because it is available to be read and modified by every instance of your app attached to a user’s iCloud account, some of which may be older versions or running on another platform, you must diligently protect a data object’s integrity. For more information, see “Exercise Caution When Using NSData Objects as Values” in iCloud Design Guide.