我见过的最奇怪的事..。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;
}现在发生的情况是,decode:中的任何NSLog语句或从decode:调用的方法都不会登录到控制台。但是,在调用decode: work之前和之后,NSLog和NSLog周围的其余代码执行得很好。我发现我可以通过注释掉所有的NSLog语句,addObject:coord;。此语句出现在它正在影响的NSLog语句之后。我还发现,通过重新安排testBoard中的几行代码,我可以让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尼斯湖怪物出现?!
发布于 2010-11-09 09:10:26
您试过在调试器中运行吗?当你到达if语句时会发生什么?
if(!_coords.count && _definition)你确定_coords.count是0而_definition不是零吗?
发布于 2010-11-09 11:54:26
根据我的经验,NSLog宏扩展可能失败。大多数情况下,原因是显而易见的,有时不是。就像这样做:
id objToLog = /* whatever */;
NSLog(@"%@", objToLog);如果此方法有效,您可以继续您的开发,也许您稍后会解决问题。
https://stackoverflow.com/questions/4131509
复制相似问题