Haoest
Haoest

Reputation: 13916

objective-c: NSMutableString must start with a \n character

Okay, this is weird as hell, and I just want a sanity check to prove that I am not hallucinating from the lack of sleep.

NSMutableString *s = [NSMutableString stringWithFormat:@""];
for(int i=0; i<9; i++){
    for (int j=0; j<9; j++){
        [s appendString:[NSString stringWithFormat:@"%d ", arr[i][j]]];
    }
    [s appendString:@"\n"];
}
NSLog(s);

The Log window displays all contents in arr except the first row. If I change the first line to

NSMutableString *s = [NSMutableString stringWithFormat:@"\n"];

it prints correctly.

Any reasonable explanations?

Upvotes: 1

Views: 183

Answers (1)

Jonathan Sterling
Jonathan Sterling

Reputation: 18385

From my comment: Is it possible that the first element of the array is being printed, but it's coming right after the timestamp in the log and you're not noticing it?

Upvotes: 1

Related Questions