Join Todd Perkins for an in-depth discussion in this video Save and load iCloud key-value pairs, part of Developing for the Apple iCloud API with iOS.
- To save data to and load data from user defaults,…we're going to create a reference to our KeyValue store.…So, I'll call this variable store,…and it's going to be an NSUbiquitousKeyValueStore,…and I'm going to make it an implicitly unwrapped optional…because I'm going to define it in viewDidLoad,…and I know that it's never going to be nil.…I'm also going to create a constant.…We'll just call this key,…and this is going to be a String,…and I'll just set it equal to the String data.…This is going to be the key for our String…that we're going to save to NSUbiquitousKeyValueStore.…
So, let's go down to viewDidLoad,…and we'll initialize store by setting it equal…to NSUbiquitousKeyValueStore.defaultStore.…Of course, you don't have to capture this in a variable,…but I'm doing this because I have a low resolution…to record this movie,…and this adds a lot of extra code.…So, I'll make my code more readable by storing it like this.…I'm doing to go up to saveData,…and the first thing we want to do is make sure…that our text field is not empty or nil.…
- Working with iCloud key-value pairs
- Building an example app that accesses iCloud documents
- Saving and loading iCloud documents
- Fetching records with CloudKit