日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

谓词NSPredicate的使用

發(fā)布時(shí)間:2024/4/17 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 谓词NSPredicate的使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

? ? ? 謂詞是用來為數(shù)據(jù)添加過濾條件,從而更加精確的找到找到所描述條件的數(shù)據(jù)。蘋果為我們封裝好了NSPredicate類,我們可以很方便的得到我們需要的過濾條件。

? ? ? 謂詞的簡單語法總結(jié):

? ? ? 比較運(yùn)算:

?> 大于
< 小于
?>= 大于等于
?<= 小于等于
== 等于
!= 不等于
between 左邊的表達(dá)式等于右邊的表達(dá)式的值或者介于它們之間。 右邊是一個(gè)有兩個(gè)指定上限和下限的數(shù)值的數(shù)列 (指定順序的數(shù)列)

?

? ? ? ?

? ? ? ? ??

?

?

?

?

?

? ?

?

?

?

?關(guān)系運(yùn)算符:

ANY,SOME 指定下列表達(dá)式中的任意元素
ALL 指定下列表達(dá)式中的所有元素
NONE 指定下列表達(dá)式中沒有的元素。
IN 左邊的表達(dá)必須出現(xiàn)在右邊指定的集合中。
比如,name IN { '昊天', '望舒', '墨雪' }。
BEGINSWITH 以xx開頭
ENDSWITH 以xx結(jié)尾
CONTAINS 其中包含xx
like 匹配任意多個(gè)字符

?

?

?

?

?

?

?

?

?

?

?

?

1.查找數(shù)組中

NSArray *humans = [NSArray arrayWithObjects:[Human personWithName:@"cat" andAge:0],[Human personWithName:@"dog" andAge:1],[Human personWithName:@"bird" andAge:2],[Human personWithName:@"tiger" andAge:3],[Human personWithName:@"lion" andAge:4],[Human personWithName:@"monkey" andAge:5],[Human personWithName:@"cow" andAge:6],[Human personWithName:@"dargen" andAge:7],[Human personWithName:@"bear" andAge:8], nil];//使用謂詞條件運(yùn)算符NSPredicate *predicate = [NSPredicate predicateWithFormat:@"age > 5"];NSArray *array1 = [humans filteredArrayUsingPredicate:predicate];//將謂詞添加到數(shù)組中NSLog(@"%@",array1);

//使用謂詞中的in進(jìn)行過濾predicate = [NSPredicate predicateWithFormat:@"name IN {'bird','lion'}"];NSArray *array2 = [humans filteredArrayUsingPredicate:predicate];NSLog(@"%@",array2);

//使用betweenpredicate = [NSPredicate predicateWithFormat:@"age between {2,5}"];NSArray *array3 = [humans filteredArrayUsingPredicate:predicate];NSLog(@"%@",array3);

//使用likepredicate = [NSPredicate predicateWithFormat:@"name like '?o*'"];//?表示一個(gè)字符串,且第二個(gè)字符串為oNSArray *array5 = [humans filteredArrayUsingPredicate:predicate];NSLog(@"%@",array5);

?

//使用BEGINSWITHpredicate = [NSPredicate predicateWithFormat:@"name beginswith 'd'"];NSArray *array4 = [humans filteredArrayUsingPredicate:predicate];NSLog(@"%@",array4);

轉(zhuǎn)載于:https://www.cnblogs.com/moxuexiaotong/p/4972511.html

總結(jié)

以上是生活随笔為你收集整理的谓词NSPredicate的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。