fetchRequestFromTemplateWithName变量 [英] fetchRequestFromTemplateWithName variables

查看:180
本文介绍了fetchRequestFromTemplateWithName变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xcode 4.2.1并尝试使用一个变量。我理解在xcode 4,你需要设置变量 $ variable 。我在Xcode中为我的获取请求变量为 $ currDate

I'm using Xcode 4.2.1 and trying to use a variable. I understand in xcode 4 you need to set the variable with $variable. I have in Xcode for my fetch request the variable as $currDate

,我的代码为

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"YYYYMMdd"];
    NSDate *currDate = [NSDate date];
    NSString *currDateString = [dateFormatter stringFromDate:currDate];
    NSError *error;
    NSFetchRequest *fetchRequest = [[[DataManager sharedInstance] objectModel] fetchRequestFromTemplateWithName:@"fetchAppointmentsByDate" substitutionVariables:[NSDictionary dictionaryWithObject:currDateString forKey:@"currDate"]];
     NSLog(@"Fetch Request: %@", fetchRequest);
    NSArray *appts = [[[DataManager sharedInstance] managedObjectContext] executeFetchRequest:fetchRequest error:&error];
    NSLog(@"Fetch Request Results: %i %@ - %@", [appts count], appts, error);

但是它不返回任何结果,我知道结果。

However it is not returning ANY results and I know results are there.

日志:

2012-02-24 14:16:29.332 MyApp[2687:fb03] Fetch Request: <NSFetchRequest: 0xb7641c0> (entity: Appointments; predicate: (date == "$currDate"); sortDescriptors: ((null)); type: NSManagedObjectResultType; )
2012-02-24 14:16:29.334 MyApp[2687:fb03] Fetch Request Results: 0 (
) - (null)

我在这里做了一些工作,我在上面的Xcode的屏幕截图中找到了 c $ c> $ currDate 到 20120224 < xcode中的获取请求模板的变量是否错误4.2?

Am I doing the variable thing for fetch request templates wrong in xcode 4.2?

UPDATE 1:

这个?

推荐答案

单击属性名称,在您的情况下 date 并在弹出菜单中选择表达式。

Click on the attribute name which in your case is date and select "Expression" in the popup menu. That allows you to input the variables.

在您的情况下,将Expression字段设置为: date == $ currDate

In your case set the Expression field to: date == $currDate

这对我有用。

编辑:为了更像Xcode 3树型的情况,下拉选项键,您可以以相同的方式添加子谓词。当您按住选项键时,+号会变成...:

To get more like Xcode 3 tree type of situation, you hold down the option key, you can add a sub-predicates in the same way. The '+' sign changes to the "..." when you hold the option key down like so:

您可以实现相同的结果。

You can achieve the same result that way.

这篇关于fetchRequestFromTemplateWithName变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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