任何人都可以通过获取结果来帮助解决此错误吗? [英] Can Anyone Help With This Error With Fetch Results?

查看:37
本文介绍了任何人都可以通过获取结果来帮助解决此错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过获取结果来帮助解决此错误吗?

Can Anyone Help With This Error With Fetch Results?

我收到一条错误消息:" * 由于未捕获的异常'NSInvalidArgumentException'终止了应用程序,原因:'实体'''中的键路径例程在 if(![self.fetchedResultsController performFetch:& error]).

I am getting error that says: "* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath Routine not found in entity '" at line if (![self.fetchedResultsController performFetch:&error]) .

方法:

    - (NSFetchedResultsController *)fetchedResultsController
{
    if (fetchedResultsController != nil)
    {
        return fetchedResultsController;
    }

    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    [fetchRequest setPredicate:[NSPredicate predicateWithFormat: @"Routine == %@",theSelectedRoutine]];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

    // Edit the sort key as appropriate.
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    // Edit the section name key path and cache name if appropriate.
    // nil for section name key path means "no sections".
    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];

    NSError *error = nil;
    if (![self.fetchedResultsController performFetch:&error])
    {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return fetchedResultsController;
} 

推荐答案

您的实体锻炼没有属性 Routine .这很可能是大小写不匹配.属性应以小写开头,例如 routine .

Your entity Exercise does not have a property Routine. Most likely this is a case-mismatch. Properties should begin with a lowercase like routine.

也可能没有诸如 Exercise 之类的实体.确保 entity 不为空.

It is also possible that there is no such entity as Exercise. Make sure that entity is not nil.

这篇关于任何人都可以通过获取结果来帮助解决此错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆