Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-核心数据自动生成模型-无法识别的选择器_Ios_Core Data_Selector_Nsmanagedobject - Fatal编程技术网

iOS-核心数据自动生成模型-无法识别的选择器

iOS-核心数据自动生成模型-无法识别的选择器,ios,core-data,selector,nsmanagedobject,Ios,Core Data,Selector,Nsmanagedobject,我有一个基本的核心数据模型,如下所示: 我自动生成了数据模型文件,它给了我类似的东西: BSStudent.h // // BSStudent.h // #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @class BSFormation; @interface BSStudent : NSManagedObject @property (nonatomic, retain) NS

我有一个基本的核心数据模型,如下所示:

我自动生成了数据模型文件,它给了我类似的东西:

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对象:

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:]:无法识别的选择器发送到实例0x1F02E00


有人知道这里发生了什么吗?

一种可能的解释是,您在以下内容中使用了错误的字符串:

BSStudent *newStudent = (BSStudent *)[NSEntityDescription entityForName:kBSStudent inManagedObjectContext:self.managedObjectContext];
尝试并检查
newStudent
实际上是什么:

BSStudent *newStudent = (BSStudent *)[NSEntityDescription entityForName:kBSStudent inManagedObjectContext:self.managedObjectContext];
NSLog(@"New Student: %@", [newStudent description]);
newStudent.firstname = firstname;

也许它会澄清一些事情…

似乎对
newStudent很好。描述
2013-01-26 16:49:34.641 Bulletin scolaire[3203:907]()名称BSStudent,managedObjectClassName BSStudent,重命名标识符BSStudent,Isastract 0,超级实体名称(null)[……]
也许您使用的是旧版本的模型,出于某种原因。。。您是否尝试过清理项目、从设备中删除应用程序并重新生成/运行?刚刚测试过清理项目+从设备中删除应用程序=>相同的结果:(我发现问题出在哪里。我使用的是
[NSEntityDescription entityForName:…]
而不是
[NSEntityDescription insertNewObjectForEntityForName:…]
.Thx感谢您的帮助sergio
BSStudent *newStudent = (BSStudent *)[NSEntityDescription entityForName:kBSStudent inManagedObjectContext:self.managedObjectContext];
NSLog(@"New Student: %@", [newStudent description]);
newStudent.firstname = firstname;