Xcode, Why are some NSLog entries omitted from the console?

I'm just starting to learn the development of iOS. Every time I run this program, the console does not always display my NSLogs.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {

        NSMutableArray *items = [[NSMutableArray alloc] init];

        [items addObject:@"One"];
        [items addObject:@"Two"];
        [items addObject:@"Three"];

        [items insertObject:@"zero" atIndex:0];

        NSLog(@"Object at 0 is %@", [items objectAtIndex:0]);
        NSLog(@"Object at 1 is %@", [items objectAtIndex:1]);
        NSLog(@"Object at 2 is %@", [items objectAtIndex:2]);
        NSLog(@"Object at 3 is %@", [items objectAtIndex:3]);

        for (int i = 0; i < [items count]; i++) {
            NSLog(@"%@", [items objectAtIndex:i]);
        }
        items = nil;           
    }
    return 0;
}

I have to get this in the console every time I run it:

2012-04-11 16:29:10.419 RandomPossessions[701:403] Object at 0 is zero
2012-04-11 16:29:10.421 RandomPossessions[701:403] Object at 1 is One
2012-04-11 16:29:10.422 RandomPossessions[701:403] Object at 2 is Two
2012-04-11 16:29:10.422 RandomPossessions[701:403] Object at 3 is Three
2012-04-11 16:29:10.423 RandomPossessions[701:403] zero
2012-04-11 16:29:10.423 RandomPossessions[701:403] One
2012-04-11 16:29:10.424 RandomPossessions[701:403] Two
2012-04-11 16:29:10.424 RandomPossessions[701:403] Three

But sometimes this is not all displayed. Another time, I ran it and I could just get:

2012-04-11 16:48:20.626 RandomPossessions[734:403] Object at 0 is zero
2012-04-11 16:48:20.628 RandomPossessions[734:403] Object at 1 is One

I need to run the program several times to get a complete list of NSLogs for output to the console. Is this a mistake, or am I doing something wrong? Thanks

+3
source share
2 answers

Exciting. I just tried my code and got the same result. Here is my hypothesis:

Set a breakpoint on your line:

    [items insertObject:@"zero" atIndex:0];

When the debugger gets there, the debug panel shows one thread.

Now go to

    NSLog(@"Object at 1 is %@", [items objectAtIndex:1]);

3 .

, 2 . , , , .

sleep(0);

, .

, , , .

: , . iOS, . .

.

+5

fflush() :

fflush(stdout);

NSFileHandle:

[[NSFileHandle fileHandleWithStandardOutput] synchronizeFile];
+3
source

All Articles