NSPredicate
NSPredicate 用于描述一个过滤/判断条件。你会在很多“过滤/筛选”API 中遇到它(例如 filteredSetUsingPredicate、filterUsingPredicate、filteredOrderedSetUsingPredicate 等)。
类成员 (Class members)
Section titled “类成员 (Class members)”predicateWithFormat
Section titled “predicateWithFormat”从格式字符串创建谓词。
static predicateWithFormat(predicateFormat: string): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
predicateFormat | string | 谓词格式(如 “age > 18”)。 |
Return Value:
NSPredicate: 新谓词实例。
predicateWithFormatArgumentArray
Section titled “predicateWithFormatArgumentArray”从格式与参数数组创建。
static predicateWithFormatArgumentArray(predicateFormat: string, arguments: NSArray): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
predicateFormat | string | 谓词格式。 |
arguments | NSArray | 参数数组。 |
Return Value:
NSPredicate: 新谓词实例。
predicateWithFormatArguments
Section titled “predicateWithFormatArguments”从格式与可变参数创建。
static predicateWithFormatArguments(predicateFormat: string, argList: any): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
predicateFormat | string | 谓词格式。 |
argList | any | 参数列表。 |
Return Value:
NSPredicate: 新谓词实例。
predicateFromMetadataQueryString
Section titled “predicateFromMetadataQueryString”从元数据查询字符串创建。
static predicateFromMetadataQueryString(queryString: string): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
queryString | string | 查询字符串。 |
Return Value:
NSPredicate: 新谓词实例。
predicateWithValue
Section titled “predicateWithValue”创建恒真/恒假谓词。
static predicateWithValue(value: boolean): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
value | boolean | true 为恒真,false 为恒假。 |
Return Value:
NSPredicate: 新谓词实例。
predicateWithBlock
Section titled “predicateWithBlock”从 block 创建谓词。
static predicateWithBlock(block: (object: any, bindings: any) => boolean): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
block | (object, bindings) => boolean | 对每个对象调用的判断块。 |
Return Value:
NSPredicate: 新谓词实例。
实例成员 (Instance members)
Section titled “实例成员 (Instance members)”predicateFormat
Section titled “predicateFormat”谓词格式字符串。
predicateFormat(): stringReturn Value:
string: 格式字符串。
predicateWithSubstitutionVariables
Section titled “predicateWithSubstitutionVariables”用变量绑定生成新谓词。
predicateWithSubstitutionVariables(variables: NSDictionary): NSPredicateParameters:
| Name | Type | Description |
|---|---|---|
variables | NSDictionary | 变量名到值的映射。 |
Return Value:
NSPredicate: 新谓词实例。
evaluateWithObject
Section titled “evaluateWithObject”对对象求值。
evaluateWithObject(object: any): booleanParameters:
| Name | Type | Description |
|---|---|---|
object | any | 要测试的对象。 |
Return Value:
boolean: 是否满足谓词。
evaluateWithObjectSubstitutionVariables
Section titled “evaluateWithObjectSubstitutionVariables”对对象与变量绑定求值。
evaluateWithObjectSubstitutionVariables(object: any, bindings: NSDictionary): booleanParameters:
| Name | Type | Description |
|---|---|---|
object | any | 要测试的对象。 |
bindings | NSDictionary | 变量绑定。 |
Return Value:
boolean: 是否满足谓词。
allowEvaluation
Section titled “allowEvaluation”允许求值(安全相关,较少直接调用)。
allowEvaluation(): voidReturn Value:
- 无。