我有一个基本的核心数据模型,如下所示:
我自动生成数据模型文件,它给了我类似的东西:
BSStudent.h
//
// BSStudent.h
//
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class BSFormation;
@interface BSStudent : NSManagedObject
@property (nonatomic, retain) NSString * firstname;
@property (nonatomic, retain) NSString * lastname;
@property (nonatomic, retain) NSDate * birthdate;
@property (nonatomic, retain) id thumbnail;
@property (nonatomic, retain) NSSet *formations;
@end
@interface BSStudent (CoreDataGeneratedAccessors)
- (void)addFormationsObject:(BSFormation *)value;
- (void)removeFormationsObject:(BSFormation *)value;
- (void)addFormations:(NSSet *)values;
- (void)removeFormations:(NSSet *)values;
@end
BSStudent.m
//
// BSStudent.m
//
#import "BSStudent.h"
#import "BSFormation.h"
@implementation BSStudent
@dynamic firstname;
@dynamic lastname;
@dynamic birthdate;
@dynamic thumbnail;
@dynamic formations;
@end
我尝试通过执行以下操作来简单地保存 BSStudent 对象:
BSStudent *newStudent = (BSStudent *)[NSEntityDescription entityForName:kBSStudent inManagedObjectContext:self.managedObjectContext];
newStudent.firstname = firstname;
newStudent.lastname = lastname;
newStudent.birthdate = birthdate;
newStudent.thumbnail = thumbnail;
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Error: %@", [error localizedDescription]);
}
但我的应用程序总是因错误而崩溃:[NSEntityDescription setFirstname:]: unrecognized selector sent to instance 0x1f021e00
有人弄清楚这里发生了什么?