How to use iCloud to store Key/Value Data

iCloud-IconUsing iCloud as Key/Value storage is almost identical to NSUserDefaults, except it populates to iCloud in the background and can be read from any device on the same account. What I find much harder than the code is how to make this work in Xcode.

Here’s what we need:

  • an App ID that has iCloud enabled
  • a Provisioning Profile for this App ID
  • an entitlements file, created by Xcode
  • code to save data
  • code to retrieve data

The Code

Let’s start with the easy bit. To store and retrieve key/value data in iCloud we use the

This content is for members only.

In here, select your Apple ID and hit View Details. This will list all signing identities and Provisioning Profiles. You have the option to add more identities, or refresh existing profiles.

You can also head over to Editor – Provisioning Profiles – Import if you’d like to add a profile manually.

Adding iCloud Entitlements

In Xcode 4.6.3 you need to head over to your target and in the Entitlements section, tick the Entitlements box. This will generate a .entitlements file in Xcode that you won’t have to worry about. Underneath it check the “Use iCloud” box, as well as the “Use Key/Value Store” box.

Xcode will also want to know which store identifier you want to use. In our example it’ll match the App ID’s reverse domain Bundle Identifier, but I understand that it can be something else, so that two apps with different identifiers can share the same data. I haven’t tried this though, so don’t quote me on it.

This content is for members only.

Happy iClouding!





One thought on “How to use iCloud to store Key/Value Data

  1. I’ve just found out that in Xcode 5 the section for refreshing amended profiles has moved to
    Xcode – Preferences – Accounts.

    In here, select your Apple ID and hit View Details. This will list all signing identities and Provisioning Profiles. You have the option to add more identities, or refresh existing profiles.

Leave a Reply