关于coredata
来源:低调,爆发! 责任编辑:栏目编辑 发表时间:2013-07-02 05:18 点击:次
今天学习了core data tutorial for ios,大致了解了core data的工作原理,觉得tutorial最后一部分的建议对加强core data的理解和使用很有帮助,先记录下来,等正式用到的时候可以学习学习!
Programming Guide).
If you add a photograph, consider the memory management implications of fetching a photograph with every Event you retrieve from the store. Core Data has a feature called faulting (see Managed Objects in Core Data Programming Guide) which means that it doesn’t have to complete the object graph. You would typically model the photograph as a separate entity, with a relationship from the Event entity to the Photo entity (and a reciprocal relationship from the photo to the event). When you retrieve just a single Event object, the photo relationship may be represented by a fault. If you ask an event for its photo, Core Data automatically fulfills the fault and retrieves the corresponding data for you. See PhotoLocations for an example.
Changing the Model Means you Cannot Open Existing Stores:
If you change the schema in your managed object model, your application typically won’t be able to open files you created with an earlier version. This is an issue that you might address as your experience grows (see Core Data Model Versioning and Data MigrationProgramming Guide).
The Core Data Utility Tutorial
It’s worth turning away from iOS for a short while and working through Core Data Utility Tutorial. It’s similar in many respects to this tutorial, but it’s freed from the distraction of a user interface. It introduces a couple of new concepts regarding the lifecycle of a managed object, and reinforces the idea of the managed object model being just a collection of objects—by having you create one programatically.Use a Fetched Results Controller
Try to update the Locations application to use an NSFetchedResultsController object. A fetched results controller is intended primarily to make fetching large numbers of objects much more efficient, but it’s worth practicing using one with a smaller data set. For comparison, look at the CoreDataBooks example.Creating a Managed Object Model with Xcode
Work through the tutorial Creating a Managed Object Model with Xcode. You will learn more about the Xcode tools for Core Data, and in particular how to establish relationships between entities. This will be essential if you want to create applications that contain entities that are related to each other, as suggested in “A Drill-Down Interface”.A Drill-Down Interface
Extend the Locations application to provide a drill-down interface to allow users to inspect an event—perhaps to edit comments or a add photograph. You need to add more properties to the Event entity, and perhaps a second entity. The TaggedLocations sample provides an example of using a second entity with a to-many relationship.If you add a photograph, consider the memory management implications of fetching a photograph with every Event you retrieve from the store. Core Data has a feature called faulting (see Managed Objects in Core Data Programming Guide) which means that it doesn’t have to complete the object graph. You would typically model the photograph as a separate entity, with a relationship from the Event entity to the Photo entity (and a reciprocal relationship from the photo to the event). When you retrieve just a single Event object, the photo relationship may be represented by a fault. If you ask an event for its photo, Core Data automatically fulfills the fault and retrieves the corresponding data for you. See PhotoLocations for an example.
Add an Add Sheet
An Add sheet allows you to enter more information about an event when you create it. Think about what information you might pass to the Add sheet controller. Think also about how you might keep the edits made to the Event object in the Add sheet discrete from edits made in the rest of the application. (Hint: you might consider using two managed object contexts—see the CoreDataBooks example).本文出自 “低调,爆发!” 博客,请务必保留此出处http://life173.blog.51cto.com/2035365/435469
相关新闻>>
- 发表评论
-
- 最新评论 更多>>