关于coredata

原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://life173.blog.51cto.com/2035365/435469
今天学习了core data tutorial for ios,大致了解了core data的工作原理,觉得tutorial最后一部分的建议对加强core data的理解和使用很有帮助,先记录下来,等正式用到的时候可以学习学习!

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 Migration
Programming 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值