views:

512

answers:

2

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

+3  A: 

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
The problem is, that the NSLog will be created in an other class...
Flocked
whereever are you creating the NSlog, it will be populated from some variables, right?
Nithin
Make class `A` contain an `NSString *` property called `stringToBeLogged` (or whatever). Then you just access it from class `B` via `instanceOfClassA.stringToBeLogged`.
Alex Reynolds
A: 

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