Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
This hour shows you how to work with the second implementation of a universal app. It explores the document model of apps on Mac OS and iOS as well as the non-document model (sometimes called the Library/Shoebox model). Both let you store data in any way you want, although Core Data is clearly preferable because of its power and flexibility. The structure of the two types of apps differ, but those differences are confined to the app delegate and document classes—your data model, views, view controllers, and nib files work the same way no matter in which structure they are located.
| Q. | Where does the Core Data stack go in each of the app structures? |
| A. | The Core Data stack needs to be always reachable from code that might need it. Thus, it is located in the document class for a document-based app and in the app delegate for a Library/Shoebox app. Each document can have its own Core Data stack—and that is one of the features of the document-based architecture. |
| Q. | How do you share data models? |
| A. | Data models are portable from one app to another because they do not contain references to classes or nib files. Classes contain references to the data model, and nib files contain connections to outlets in classes and through them to the data model. The data model itself is transportable. Having transported it, you and your users can then use it in several apps to access the same files. But remember that Core Data is not a multiuser environment; you can access the same files but not at the same time. You can look at the iCloud information on developer.apple.com and the author’s site at northcountryconsulting.com to see how you can take advantage of iCloud. |