Predicate 謂詞 斷言

2021-07-11 18:20:28 字數 1306 閱讀 4230

nspredicate

在foundation框架中,提供了乙個nspredicate類,可以指定過濾條件,通過指定的過濾條件可以對集合中的物件進行篩選過濾;

nspredicate的查詢方式類似於資料庫的查詢,可以使用比較和邏輯運算子,還可以使用一些關鍵字;

1 建立

+ (nspredicate )predicatewithformat:(nsstring )predicateformat;

2 使用

-(bool)evaluatewithobject:(id)object;

@property(nonatomic)int pid;

@property(nonatomic,copy)nsstring name;

@property(nonatomic)int age;

person *p1 = [[person alloc]init];

p1.pid = 1;

p1.name = @」tom」;

p1.age = 18;

person *p2= [[person alloc]init];

p1.pid = 2;

p1.name = @」james」;

p1.age = 20;

person *p3 = [[person alloc]init];

p1.pid = 3;

p1.name = @」nick」;

p1.age = 25;

nspredicate *pre = [nspredicate predicatewithformat:@」age = %d」, 20];

nsarray *array = @[p1,p2,p3];

for(person *per in array)

陣列過濾器

-(nsarray )filteredarrayusingpredicate:(nspredicate );

array = [array filteredarrayusingpredicate:pre]

(覆蓋下description)

-(nsstring *)description

4. 格式說明符

%d %@; @k(key)

nspredicate *pre = [nspredicate predicatewithformat:@」%k==%d && %k=%@」, @」age」,20,@」name」,@」tom」];

運算子:between self

字串運算子:beginwith/endwith/contains/like

謂詞的使用 predicate

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

Gateway閘道器 Predicate斷言配置

判斷時間在after配置的時間之後規則才生效 spring cloud gateway routes id after route uri predicates after 2017 01 20t17 42 47.789 07 00 america denver 判斷在before之前路由配置才生效...

謂詞篩選表示式的擴充套件庫PredicateLib

predicatelib是謂詞篩選表示式expression 的乙個擴充套件庫,它可以幫你建立乙個複雜且靈活的expression 以作為ef mongodb driver等orm框架的查詢條件。1.1 true或false predicatevar predicate predicate.true...