I am facing a strange problem with this UTF8String:
parentMode = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
…
if(parentMode != @"Sleep")
{
NSLog(@"%s", [parentMode UTF8String]);
}
My questions are:
-
Why do I have to do this conversion in order to log
parentMode? -
The log is printing
Sleep. So how is that if is done anyway?
You can’t compare strings using the normal relational operators, you must use:
You may want to check that
parentModeis notnilbefore using that method, however. You don’t need to use theUTF8Stringmethod, you can log the string directly using the%@format specifier. If this is not working, then there is something very important that you are omitting from the code you provided.