简体   繁体   中英

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.

The value expression for that BOOL field that should do the trick is $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

So I add parenteses: ($source.stringName == "Specific string value").

XCode keeps complaining, now about "($source.stringName == "Specific string value") == 1" having a bad syntax. 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 isBoolValue= [myStringValue boolValue];

And then compare 2 BOOL value such like ,

if(firtBoolValue == isBoolValue)
{
  //  compare;
}
else
{
  // not compare;
}

If you want to NSString Comparison then

First you need to convert BOOL to NSString , such like

NSString *stringValue = [NSString stringWithFormat:@"%@",myBoolValue ? @"YES" : @"NO"];

Then after put condition like,

if([myFirstString isEqualToString:stringValue])
{
  // compre
}
else
{
  // not compre 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM