oc謂詞過濾元素

2021-08-20 22:31:52 字數 724 閱讀 1281

謂詞的乙個常用功能就是對集合進行過濾,當程式使用謂詞對集合進行過濾時,程式將會自動遍歷集合元素,並根據集合元素來計算謂詞的值,只有當根據某個集合元素計算謂詞並返回yes時,該集合元素才會被保留下來。

nsarray 提供了如下方法使用謂詞來過濾集合:

- (nsarray *)filteredarrayusingpredicate:(nspredicate *)predicate:使用指定的謂詞過濾nsarray集合,返回該集合中符合謂詞條件的元素組成新集合。

nsmutablearray提供了以下方法使用謂詞來過濾集合:

- (void) filterusingpredicate:(nspredicate *)predicate:使用指定的謂詞過濾nsmutablearray 集合,剔除該集合中不符合條件的元素。

nsset:

-(nsset *)filteredsetusingpredicate:(nspredicate *)predicate:使用指定的謂詞過濾nsset集合,返回該集合中符合謂詞條件的元素組成新集合。

- (void) filterusingpredicate:(nspredicate *)predicate:使用指定的謂詞過濾nsmutableset集合,剔除該集合中不符合條件的元素。

#import int main(int argc, const char * argv) 

return 0;

}

OC語法 謂詞NSPredicate類

cocoa中提供了nspredicate類,指定過濾器的條件。將符合條件的物件保留下來。下列列舉常用的nspredicate類的常用方法 person類含有name和age屬性 初始化乙個物件陣列 nsmutablearray array nsmutablearray array for int i...

iOS開發 NSPredicate 謂詞過濾

一 根據模型條件過濾陣列 nsmutablearray marr nsmutablearray alloc init testmodel t1 testmodel alloc init t1.age 1 testmodel t2 testmodel alloc init t2.age 3 testm...

使用CoreData查詢資料 謂詞過濾,排序操作

主要是對於nspredicate的介紹 一 nspredicate的基本語法 二 使用coredata查詢資料 謂詞過濾,排序操作 一 nspredicate的基本語法 nspredicate類是用來定義邏輯條件約束的獲取或記憶體中的過濾搜尋。可以使用謂詞來表示邏輯條件,用於描述物件永續性儲存在記憶...