AMH
AMH

Reputation: 6451

Why does nspredicate crash?

I wanted to check if a field contains data or not. Here's my code:

[fetchRequest setPredicate:[NSPredicate predicateWithFormat:
                            @"( SeriesStudyID ==  %@ )" ,"" ]];

But it crashes. Why?

Upvotes: 3

Views: 737

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

@iAnand's answer is wrong. Using %@ in a predicate format string is perfectly acceptable.

The problem is that %@ means to substitute in an object, but you're substituting in "", which is not an object, but a char*. Thus, you need to simply add an @ sign in front of the double quotes to turn it from a char* into an NSString.

Upvotes: 4

Related Questions