nspredicate
謂詞工具一般用于過濾數組資料,也可用來過濾coredata查詢出的資料.
1). 支援keypath
2). 支援正規表達式
在使用之前先建立3個類 teacher info address,詳細代碼如下
info.h
info.m
address.h
address.m
teacher.h
teacher.m
初始化資料并添加進數組中
開始正式的使用謂詞
[1] 比較操作 (>,<,>=,<=,=)
[2] 字元串正常操作 (beginswith,endswith,contains)
@"name beginswith[cd] 'y'"
@"name endswith[cd] 'x.'"
@"name contains[cd] 'x'"
[3] 範圍 (between,in)
@"age between {10, 20}"
@"age in {10, 20}" //這個不确定是什麼
[4] 通配符 (like)
注:使用?表示一個字元,*表示多個字元
@"name like[cd] '*x*'"
[5] 邏輯運算 (and,or,not)
@"age <= 22 and name like[cd] '*x*'"
[6] 正規表達式
注:^y.+.$ 以y開頭,以.結尾的字元
@"self.name matches '^y.+.$'"
[7] keypath