Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4 Core Data: How to use fetched property created in Data Model editor

Tags:

People also ask

What is fetched property in Core Data?

Fetched Properties in Core Data are properties that return an array value from a predicate. A fetched property predicate is a Core Data query that evaluates to an array of results.

Can I add Core Data to existing project?

The first step in working with Core Data is to create a data model file to define the structure of your app's objects, including their object types, properties, and relationships. You can add a Core Data model file to your Xcode project when you create the project, or you can add it to an existing project.

What is codegen in Core Data?

Class DefinitionThis configuration is the default Codegen configuration when you create an entity in the data model editor. With this configuration, Xcode will automatically generate the required NSManagedObject subclass as part of the project's derived data.


How do you implement a fetched property in Xcode 4?

Here is an example of two entities, a book and a page: enter image description here

I followed the guidelines here to create a fetched property that references a value from the source entity using the variable $FETCH_SOURCE: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html

Now, once I have this saved and I generate the source code I get this:

//  Book.h  #import <Foundation/Foundation.h> #import <CoreData/CoreData.h>  @class Pages;  @interface Book : NSManagedObject { @private } @property (nonatomic, retain) NSString * title; @property (nonatomic, retain) NSNumber * pageCount; @property (nonatomic, retain) Pages * pages;  @end 

And...

//  Book.m  #import "Book.h" #import "Pages.h"   @implementation Book @dynamic title; @dynamic pageCount; @dynamic pages;  @end 

Where is the fetched property 'fetchLastPage'? How can I use it in code?