我始终以代码形式创建我的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模型中的变量替换
发布评论