[英]What is the syntax of a string compare in a value expression
I am trying to migrate a simple core data model using a mapping mode. 我正在尝试使用映射模式迁移简单的核心数据模型。
I have added a BOOL field, which will be true if another field has certain specific string values. 我添加了一个BOOL字段,如果另一个字段具有某些特定的字符串值,则该字段将为true。
The value expression for that BOOL field that should do the trick is $source.stringName == "Specific string value". 该BOOL字段应该完成操作的值表达式为$ source.stringName ==“ Specific string value”。
XCode however complains about "$source.stringName == "Specific string value" == 1" having a bad syntax: Unable to parse the format string XCode抱怨“ $ source.stringName ==“ Specific string value” == 1“语法错误:无法解析格式字符串
So I add parenteses: ($source.stringName == "Specific string value"). 因此,我添加了括号:($ source.stringName ==“特定字符串值”)。
XCode keeps complaining, now about "($source.stringName == "Specific string value") == 1" having a bad syntax. XCode现在一直抱怨“(($ source.stringName ==“ Specific string value”)== 1“)语法错误。 So, what is the correct syntax to test a string value against an entity field?
那么,针对实体字段测试字符串值的正确语法是什么?
You you want to compare BOOL
to NSString
then convert you string value in to BOOL
such like, 您要将
BOOL
与NSString
进行比较,然后将您的字符串值转换为BOOL
,例如,
BOOl isBoolValue= [myStringValue boolValue];
And then compare 2 BOOL
value such like , 然后比较2个
BOOL
值,例如
if(firtBoolValue == isBoolValue)
{
// compare;
}
else
{
// not compare;
}
If you want to NSString
Comparison then 如果要对
NSString
比较
First you need to convert BOOL
to NSString
, such like 首先,您需要将
BOOL
转换为NSString
,例如
NSString *stringValue = [NSString stringWithFormat:@"%@",myBoolValue ? @"YES" : @"NO"];
Then after put condition like, 然后把像这样的条件
if([myFirstString isEqualToString:stringValue])
{
// compre
}
else
{
// not compre
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.