-1

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 ;)

Flocked
  • 1,898
  • 2
  • 36
  • 57
  • What are you giving inside the NSLog function,from the question i assume that it is a sreing, but from where that string originate, is that from a variable or are you giving it implicitely – Nithin Jan 05 '10 at 09:45

2 Answers2

3

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...");
}
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
  • whereever are you creating the NSlog, it will be populated from some variables, right? – Nithin Jan 05 '10 at 09:48
  • Make class `A` contain an `NSString *` property called `stringToBeLogged` (or whatever). Then you just access it from class `B` via `instanceOfClassA.stringToBeLogged`. – Alex Reynolds Jan 05 '10 at 09:51
0

You could consider creating your own custom log function which calls NSLog() after checking for your string constant. This would keep your code a bit cleaner if you want this functionality in multiple places and also allows you to easily extend the logging function further if desired.

mikecsh
  • 852
  • 7
  • 12