Database Reference
In-Depth Information
Note: Xcode may be telling you that an App ID with identifier
iCloud.com.razeware.CloudNotes is not available. This probably means
you're not the first person in the universe to attempt this tutorial and the
name is taken!
If that's the case, switch to the General tab and amend the bundle identifier
to something a little more personal, like
com.razeware.yourname.CloudNotes . Switch back to Capabilities and
click the Fix Issue button, and you should be all good.
You are free to change this name; however, remember that if you change the
container name between versions of your app, previous versions and other
applications referencing this container name will no longer be able to sync with the
new versions.
You've completed the application setup! That was easy. :] It's time to configure the
code to use iCloud to sync data.
The cloud stack
Open NotesListViewController.swift and find the stack property near the top of
the class definition. This is where the app lazily loads the Core Data stack.
Replace the property declaration and initialization code with the following:
lazy var stack : CoreDataStack = {
let options =
[ NSPersistentStoreUbiquitousContentNameKey : "CloudNotes" ,
NSMigratePersistentStoresAutomaticallyOption : true ,
NSInferMappingModelAutomaticallyOption : true ]
let stack = CoreDataStack (modelName: "CloudNotesDataModel" ,
storeName: "CloudNotes" ,
options: options)
return stack
}()
Here, you use the NSPersistentStoreUbiquitousContentNameKey value to uniquely
identify the persistent store in the cloud and across devices. This means you can
have several named “data buckets” in your app's ubiquity container. This would be
helpful if, for example, you had an iOS app that only accessed a subset of the data
from a Mac app.
Believe it or not, you now have a Core Data app with iCloud syncing enabled! This
is far easier than in previous versions of the API, as Apple has essentially taken
control of all the error-prone setup previously involved with this process. Don't
 
Search WWH ::




Custom Search