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

这一生的挚爱 提交于 2019-12-03 03:13:43

问题


How do you implement a fetched property in Xcode 4?

Here is an example of two entities, a book and a page:

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?


回答1:


From what I've read you need to add fetched properties to the generated class yourself using the @dynamic keyword

// In your header
@property (nonatomic, retain) NSArray *fetchLastPage;

// In your class
@dynamic fetchLastPage;


来源:https://stackoverflow.com/questions/6486823/xcode-4-core-data-how-to-use-fetched-property-created-in-data-model-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!