关于coredata

来源:低调,爆发! 责任编辑:栏目编辑 发表时间:2013-07-02 05:18 点击:
今天学习了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

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Lexical or Preprocessor Issue 'xxx.h
      • ios学习笔记(二)xcode 4.3.2下实现基本交互
      • ios版本的helloworld
      • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
      • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
      • IOS类似iphone通讯录TableView的完整demo【附源码】
      • UITableView一些方法
      • [iPhone中级]iPhone团购信息客户端的开发 (二)
      • iphone(object-c)内存管理(1)
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1