Search code examples
iphoneobjective-cxcodenslog

if-query: if (Nslog isEqualtoString @"...") - How can I make this?


I want my app to do something when the last NSLog has a certain string. I thought I could realize this with an if-query and isEqualtoString, but how can I make this?

Sorry for my bad English ;)


Solution

  • Maybe I don't understand what you're trying to do, but you can just create the string somewhere, log it, and then test it:

    NSInteger _someInt = 2;
    NSString *_someString = @"bananas";
    NSString *_stringToBeLogged = [NSString stringWithFormat:@"%d %@", _someInt, _someString];
    NSLog(@"%@", _stringToBeLogged);
    if ([_stringToBeLogged isEqualToString:@"2 bananas"]) {
        NSLog(@"I logged two bananas...");
    }