2014-03-18 65 views
1

我用这个谓词:NSPredicate格式说明问题

NSPredicate *offencePredicate = 
    [NSPredicate predicateWithFormat:@"(%@ == %@) AND (%@ == %d)", kTeamID, self.selectedTeam.teamID, kPlayerZoneID, ZoneIdTypeOffence]; 

但谓语是:

"teamID" == 10 AND "playerZoneID" == 3 

代替:

teamID == 10 AND playerZoneID == 3 

我如何可以修剪这个""当我使用用于预测的格式说明符。接下来的问题是:这是在谓词中使用表达式说明符的正确解决方案。因为我有一些API密钥对应于我的核心数据条目属性。所以可以使用常量字符串,如果我需要更改这些键中的某些键,它将允许非常快的更改,但是可以使用此常量进行预测吗?

回答

1

您需要使用%K作为密钥。

它应该是这样的:

[NSPredicate predicateWithFormat:@"(%K == %@) AND (%K == %d)", kTeamID, self.selectedTeam.teamID, kPlayerZoneID, ZoneIdTypeOffence]; 
1

使用%K

请参阅从documentation这个例子:

NSString *attributeName = @"firstName"; 
NSString *attributeValue = @"Adam"; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@", 
    attributeName, attributeValue]; 

结果:

firstName like "Adam"