gpt4 book ai didi

cocoa - "key contains $value"是什么意思?

转载 作者:行者123 更新时间:2023-12-03 17:40:56 29 4
gpt4 key购买 nike

我有一个绑定(bind)到 NSDictionaryControllerNSSearchField。在我的搜索字段的谓词格式中,我有这样的代码 key contains $value ,它是什么意思?谓词格式(代码行)还有哪些其他替代方案?谢谢!

最佳答案

快速的 search of the docs 变成了 this chapter in the Predicate Programming Guide :

Variables are denoted with a $ (for example $VARIABLE_NAME).

我没有看到任何地方明确提到它,但其含义是$ 为前缀的标识符被视为键,即通过 Key-Value Coding 检索。谓词将匹配字典 Controller 中 value for key

的对象
CONTAINS
The left-hand expression contains the right-hand expression.

包含$value的值。

那么 $value 是什么? The Cocoa Bindings Reference explains:

The multiple-value predicate binding allows you to create a search field pop-up menu that is pre populated with menu items that correspond to predicate filters. Each of the predicate bindings correspond to an entry in the search field pop-up menu. This multiple-value binding is used by the NSSearchField predicate binding.

The display name string is used as the menu item title. The predicate format is string that specifies the predicate for that menu item using the predicate format described in Predicate Programming Guide. Any occurrences of the string $value in the predicate format string are replaced with the contents of the search field.

换句话说,NSSearchField 为其谓词预定义了变量 value,以保存字段中当前存在的任何文本,即用户正在搜索的文本。

因此,例如,如果您创建格式为 name contains $value 的谓词,并且用户搜索“Emily”,则该谓词将匹配其 name 的对象code> 包含(作为子字符串)字符串“Emily”。

关于cocoa - "key contains $value"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15321668/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com