You need to use %K
for the keys.
It would look like this:
[NSPredicate predicateWithFormat:@"(%K == %@) AND (%K == %d)", kTeamID, self.selectedTeam.teamID, kPlayerZoneID, ZoneIdTypeOffence];
Domanda
I use this predicate:
NSPredicate *offencePredicate =
[NSPredicate predicateWithFormat:@"(%@ == %@) AND (%@ == %d)", kTeamID, self.selectedTeam.teamID, kPlayerZoneID, ZoneIdTypeOffence];
but the predicate is:
"teamID" == 10 AND "playerZoneID" == 3
instead of:
teamID == 10 AND playerZoneID == 3
How can I trim this ""
when I use format specifiers for predicating. And the next question is: is this the right solution using form specifiers in predicate. Because I have some API keys that are correspond to my core data entries attributes. So it is ok to use constant string that will allow quite faster changes if I need to change some of these keys, but is it ok to use this constant for predication?
Soluzione
You need to use %K
for the keys.
It would look like this:
[NSPredicate predicateWithFormat:@"(%K == %@) AND (%K == %d)", kTeamID, self.selectedTeam.teamID, kPlayerZoneID, ZoneIdTypeOffence];
Altri suggerimenti
Use %K
.
See this example from the documentation:
NSString *attributeName = @"firstName";
NSString *attributeValue = @"Adam";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",
attributeName, attributeValue];
Result:
firstName like "Adam"