我見過的最奇怪的事情.. NSLog在基於奇怪事物的方法中失敗。下面是代碼:NSLog不工作
-(void) testBoard {
BoardManager* bm = [BoardManager manager];
Board* board = [bm boardForName:@"fourteen by eight"];
NSLog(@"%@", board);
NSLog(@"%@", board.coords);
}
在Board.m
:
-(NSArray*) coords {
if(!_coords.count && _definition) {
NSArray* c = [Board decode:_definition];
[self setCoords:c];
}
return _coords;
}
+(NSArray*) decode:(NSString*)encodedCoords {
NSMutableArray* coords = [NSMutableArray array];
NSArray* tokens = [encodedCoords componentsSeparatedByString:@","];
int i = 0;
NSString* dimStr = [tokens objectAtIndex:i++];
int width = [dimStr substringToIndex:2].intValue;
int height = [dimStr substringWithRange:NSMakeRange(2, 2)].intValue;
int depth = [dimStr substringFromIndex:4].intValue;
NSLog(@"w=%d h=%d d=%d", width, height, depth);
NSString* b128;
NSString* b2;
for(int z=0; z<depth; z++) {
for(int y=0; y<height; y++) {
b128 = [tokens objectAtIndex:i++];
NSLog(@"[%@]", b128);
b2 = [Board base128to2:b128];
NSLog(@"b2=%@",b2);
for(int x=0; x<b2.length; x++) {
if([b2 characterAtIndex:b2.length-1-x] == '1') {
Coord* coord = [Coord x:width-1-x y:height-1-y z:z];
[coords addObject:coord];
}
}
}
}
return coords;
}
現在是什麼情況,沒有解碼中的NSLog語句:從所謂的解碼或方法:將登錄到控制檯。但是,在調用decode:work之前和之後,NSLog的其餘代碼執行得很好。我發現我可以簡單地通過註釋[coords addObject:coord];來獲得所有的NSLog語句。此聲明在之後出現它正在影響的NSLog語句。我還發現,我能得到的NSLog的通過重新排列在測試臺幾行的工作:是這樣的:
-(void) testBoard
{
BoardManager* bm = [BoardManager manager];
Board* board = [bm boardForName:@"fourteen by eight"];
NSLog(@"%@", board);
NSString* def = board.definition;
NSArray* coords = [Board decode:def];
NSLog(@"%@", coords);
}
這似乎相當bizarre..an Xcode中的尼斯湖水怪堆焊?