ios - predicate is getting nil, nscoredata, objective -
what doing fetch data core data following
nsstring *str; nspredicate *predicate; switch (typecube) { case newcubes: { str = [nsstring stringwithformat:@"type == %d",newcubes]; break; } case allcubes: { str = [nsstring stringwithformat:@"type != %d",customcubes]; break; } case customcubes: { str = [nsstring stringwithformat:@"type == %d",customcubes]; break; } } predicate = [nspredicate predicatewithformat:@"%@ , (accounts.keychainid == %@)", str, accountkeychainid];
however, result of predicate nil. following works
predicate = [nspredicate predicatewithformat:@"(type == %d) , (accounts.keychainid == %@)", type, accountkeychainid]; ( type either newcubes or allcubes or customcubes)
please if have ideas. comments welcomed. thanks
there class called nscompoundpredicate
allows construct predicates and, or , not operators. here need
[nscompoundpredicate andpredicatewithsubpredicates:@[predicate1, predicate2, etc.]];
so code --
nspredicate *predicate1; nspredicate *predicate; switch (typecube) { case newcubes: { predicate1 = [nspredicate predicatewithformat:@"type == %d",newcubes]; break; } case allcubes: { predicate1 = [nspredicate predicatewithformat:@"type != %d",customcubes]; break; } case customcubes: { predicate1 = [nspredicate predicatewithformat:@"type == %d",customcubes]; break; } } predicate = [nspredicate predicatewithformat:@"accounts.keychainid == %@", accountkeychainid]; [nscompoundpredicate andpredicatewithsubpredicates:@[predicate1, predicate]];
read more nscompountpredicates here: http://nshipster.com/nspredicate/
Comments
Post a Comment