Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
Core data 应用程序因核心数据的一个属性而崩溃_Core Data_Attributes_Crash - Fatal编程技术网

Core data 应用程序因核心数据的一个属性而崩溃

Core data 应用程序因核心数据的一个属性而崩溃,core-data,attributes,crash,Core Data,Attributes,Crash,我有一个很奇怪的问题。我正在使用coredata保存笔记。我可以访问/保存/编辑Notes实体的所有属性,除了一个:类别 -(void)editCategory { NSFetchRequest *request = [[NSFetchRequest alloc]init]; NSEntityDescription *categRequest = [NSEntityDescription entityForName:@"Notes" inManagedObjectContext

我有一个很奇怪的问题。我正在使用coredata保存笔记。我可以访问/保存/编辑Notes实体的所有属性,除了一个:类别

-(void)editCategory {

    NSFetchRequest *request = [[NSFetchRequest alloc]init];
    NSEntityDescription *categRequest = [NSEntityDescription entityForName:@"Notes" inManagedObjectContext:_managedObjectContext];
    request.predicate = [NSPredicate predicateWithFormat:@"text = %@", noteToEdit];
    [request setEntity:categRequest];

    //Error handling
    NSError *error = nil;
    NSMutableArray *mutableFetchResults = [[_managedObjectContext executeFetchRequest:request error:&error]mutableCopy];
    if (mutableFetchResults == nil) {
        NSLog(@"Error happened : %@", error);
    }

    Notes *editMe = [mutableFetchResults objectAtIndex:0];
    [editMe setCategory:editCategoryText];
    NSLog(@"Category from pickerview : %@", editCategoryText);
    if (![_managedObjectContext save:&error]) {
        NSLog(@"couldnt save : %@", error);
    }
}
这一行:

[editMe setCategory:editCategoryText];
正在崩溃。editCategoryText是一个字符串,作为类别属性。奇怪的是,我使用完全相同的代码来更改title属性,我没有任何问题

日志文件:

2013-11-07 15:49:20.286 Simple Notes 1[16511:a0b] -[__NSCFString managedObjectContext]: unrecognized selector sent to instance 0x8dccc30 2013-11-07 15:49:20.293 Simple Notes 1[16511:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString managedObjectContext]: unrecognized selector sent to instance 0x8dccc30'
您知道为什么此属性的行为与其他属性不同吗?谢谢。

不在计算机上,因此无法测试此功能,但:


去掉这个可变副本。executeFetchRequest返回自动删除的对象,然后您尝试复制这些对象,这会变成一个垃圾指针,它恰好指向一个字符串。

实际上,这似乎是一个核心数据错误,我通过在模拟器中删除我的应用程序,在xcode中删除核心数据模型来解决它,重新构建它并执行一次清理。

尝试使用NSArray而不是可变数组来获得结果。