- Publishing a Schema
- Creating a Sync Schema
- Data Class Properties
- Entity Properties
- Conclusion
Creating a Sync Schema
A sync schema is actually a bundle that is put together as an XCode target. The current release of XCode provides a template for building a sync schema bundle, and the settings from the template project can be duplicated as a target inside an existing application so that all the building is completed within one project as opposed to having a separate project for each module of an application. Naturally, there are arguments for both designs, and it is left up to the reader as to which process works best.
The layout of the schema’s directory structure is very similar to the layout of an Application Bundle:
myApplicationSync.syncschema myApplicationSync.syncschema/Contents myApplicationSync.syncschema/Contents/Info.plist myApplicationSync.syncschema/Contents/MacOS myApplicationSync.syncschema/Contents/MacOS/myApplicationSync myApplicationSync.syncschema/Contents/Resources myApplicationSync.syncschema/Contents/Resources/app.icns myApplicationSync.syncschema/Contents/Resources/English.lproj myApplicationSync.syncschema/Contents/Resources/English.lproj/Schema.strings myApplicationSync.syncschema/Contents/Resources/Schema.plist
The Schema.strings file is a localized file used for string replacements inside the schema itself and allows for localization of the text provided for display to the user. See Apple’s documentation on localization for more details on this file.
The Info.plist file is very straightforward and only defines the very basics for the bundle, including an icon definition that is not currently used.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>myApplicationSync</string> <key>CFBundleIconFile</key> <string>Resources/app.icns</string> <key>CFBundleIdentifier</key> <string>com.zarrastudios.myApplicationSync</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>myApplicationSync</string> <key>CFBundlePackageType</key> <string>BNDL</string> <key>CFBundleShortVersionString</key> <string>1</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>1.0</string> </dict> </plist>
The "meat," as they say, of the schema is in the Schema.plist file. This file contains all the definitions for the schema. This file is also an XML properties file just like the Info.plist file. The top-level keys are shown in the following table.
Name |
A string providing a unique name for this schema (typically, a reverse DNS-style name such as com.mycompany.SyncExamples). You should never change the schema name. Doing so orphans the old schema definition, which you then must remove. This key is required. |
DataClasses |
An array containing one or more dictionaries that describe a data class. If it is not a schema extension, this key is required. |
Entities |
An array of dictionaries describing new record types and record type extensions. |
At the top level, the schema would be as follows:
<plist version="1.0"> <dict> <key>Name</key> <string>com.zarrastudios.myApplicationSync</string> <key>DataClasses</key> <array> ... </array> <key>Entities</key> <array> ... </array> </dict> </plist>