使用FetchRequests存储在CoreData模型中的变量替换

编程入门 行业动态 更新时间:2024-10-18 10:21:43
本文介绍了使用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模型中的变量替换

本文发布于:2023-11-26 20:46:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   模型   FetchRequests   CoreData

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!