Anand
Anand

Reputation: 1983

Construct NSPredicate for NSArray of ids

I have created entity called Student in which we are storing student details.

enter image description here

I am trying to construct predicate to fetch few student details based on there ID's.

NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"Sid IN %@",@[@"1",@"2",@"3"]]];

Always getting error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "Sid IN (
    1,
    2,
    3
)"'

Upvotes: 0

Views: 52

Answers (1)

Martin R
Martin R

Reputation: 539965

You should not (and in almost all cases there is no need to) mix stringWithFormat: and predicateWithFormat:. In this case a simple

[NSPredicate predicateWithFormat:@"Sid IN %@", @[@"1",@"2",@"3"]]

should do.

Upvotes: 2

Related Questions