Cocoa-Touch, Core Data: Linker error, NSManagedObject symbol not found
I have a cocoa-touch app, using the core data framework.
I've created a xcdatamodel with two entities: Program
and ProgramReplay
.
ProgramReplay
has a relationship to Program
, and a reverse relationship exists in the later.
I've saved this, and used XCode's feature to generate the classes for these two entities. The generated headers are as follows:
#import <CoreData/CoreData.h>
@class ProgramReplay;
@interface Program : NSManagedObject
{
}
// other properties here, removed them to keep it short
@property (nonatomic, retain) NSSet* replays;
@end
@interface Program (CoreDataGeneratedAccessors)
- (void)addReplaysObject:(ProgramReplay *)value;
- (void)removeReplaysObject:(ProgramReplay *)value;
- (void)addReplays:(NSSet *)value;
- (void)removeReplays:(NSSet *)value;
@end
and
#import <CoreData/CoreData.h>
@class Program;
@interface ProgramReplay : NSManagedObject
{
}
@property (nonatomic, retain)开发者_运维知识库 NSDate * date;
@property (nonatomic, retain) Program * program;
@end
I haven't started using these two classes anywhere yet, but when I try to build them I get the following weird linking errors:
".objc_class_name_NSManagedObject", referenced from:
.objc_class_name_Program in Program.o
.objc_class_name_ProgramReplay in ProgramReplay.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
What am I doing wrong?
It looks like you haven't linked in the CoreData framework. Make sure that "CoreData.framework" is part of the "Link binary with libraries" phase of the target you're building. Also add #import <CoreData/CoreData.h>
in .h file.
精彩评论