使用FetchRequests存储在CoreData模型中的变量替换 [英] Variable Substitution with FetchRequests stored in a CoreData Model

查看:70
本文介绍了使用FetchRequests存储在CoreData模型中的变量替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我始终以代码形式创建我的NSFetchRequests。现在,我正在查看用于构建获取请求并将其存储在模型中的Xcode GUI。

I've always created my NSFetchRequests entirely in-code. Now I'm looking at the Xcode GUI for building a fetch request and storing it in the model.

我正在遵循Xcode文档中的示例。我在模型中添加了提取请求,并且通过Modeling GUI创建的谓词是:

I'm following an example from the Xcode Documentation. I added a Fetch Request to my model, and the predicate that has been created through the Modelling GUI is:

 firstName LIKE[c] "*SUBSTRING*"

然后我用以下两行检索该请求:

I then retrieve that request with these two lines:

NSDictionary *substituionDictionary = [NSDictionary dictionaryWithObject:@"woody" forKey:@"SUBSTRING"];

NSFetchRequest *fetchRequest = [mom fetchRequestFromTemplateWithName:@"firstNameContains" substitutionVariables:substituionDictionary];

生成的NSFetchRequest的NSLog输出如下:

An NSLog of the resulting NSFetchRequest outputs this:

(entity: Customer; predicate: (firstName LIKE[c] "*SUBSTRING*"); sortDescriptors: (null); limit: 0)

..表示在返回存储的FetchRequest之前未替换变量。

.. which indicates that the variable is not being substituted prior to the return of the stored FetchRequest.

因此,如何指定在Xcode数据建模获取请求谓词构建器GUI中输入的文本打算在运行时被NSFetchRequest:fetchRequestFromTemplateWithName:substitutionVariables替换:?

So, how does one specify that text entered in the Xcode Data Modelling Fetch Request Predicate Builder GUI is intended to be substituted at runtime by NSFetchRequest:fetchRequestFromTemplateWithName:substitutionVariables: ?

谢谢!

伍迪

推荐答案

您需要右键单击包含预期变量的提取请求谓词编辑器的行,然后从弹出窗口中选择 VARIABLE。在Xcode编辑器中,有时您右键单击的位置有时很挑剔,因此我倾向于单击+/-按钮左侧的位置。

You need to right-click on the row of the fetch request predicate editor containing the intended variable and select "VARIABLE" from the popup. Where you right-click is sometimes picky in the Xcode editor, so I tend to click just to the left of the +/- buttons.

这篇关于使用FetchRequests存储在CoreData模型中的变量替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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