謂詞基本使用

2022-08-20 01:00:13 字數 779 閱讀 2118

1

#pragma mark - 謂詞基本使用

2 - (void

)demo1

3 else16}

1718

#pragma mark - 匹配陣列

19 - (void

)demo2

2032

//需求:

33//

1> 姓名中包含"8"字串的名字

34//

2> 查詢年齡範圍在 18 和 22 之間的

35//

contains[cd]在匹配字串時,不區分大小寫,不區分注音符號

36//

nspredicate *predicate = [nspredicate predicatewithformat:@"age between && name contains[cd] '8'"];

3738

//使用謂詞對物件進行匹配時,是通過kvc進行匹配的,指定keypath,需要用%k

39 nspredicate *predicate = [nspredicate predicatewithformat:@"

%k contains '8'

", @"

name"];

4041

//對陣列進行過濾

42 nslog(@"

匹配結果 %@

", [arraym filteredarrayusingpredicate:predicate]);

43 }

使用 CONTAINS 謂詞

可以使用 contains 謂詞在資料庫中檢索特定的短語。當然,這樣的查詢可以使用 like 謂詞編寫。但是,contains 的許多形式所提供的文字查詢能力比 like 要強。此外,與使用 like 謂詞不同的是,contains 檢索總是區分大小寫。說明對於那些區分大小寫的語言 多數都基於拉丁語...

ios 謂詞的使用

剛入行的小女人,希望以後大家多多關照,把每天學到的知識記錄下,方便以後使用,有不對的地方希望大家多多指點,小女感激不盡。今天剛剛學了謂詞的使用,記錄下。返回乙個符合謂詞條件的陣列 nsarray newarray array filteredarrayusingpredicate predicate...

謂詞的使用 predicate

原文 一 運算子 1 between 比較運算子 nspredicate predicate nspredicatepredicatewithformat age 3 2 and 與 or 或 not 非 邏輯運算 nspredicate predic nspredicatepredicatewit...