开发者

objective-c function is not executed well

This function is not executed well.

-(void开发者_如何学运维)sampleItemA:(NSString*)a itemB:(NSString*)b itemC:(NSDate*)c{
    NSLog(@"A");
    NSArray* ary = [[NSArray alloc] initWithObjects:a, b, c, nil];
    NSLog([ary description]);
    NSLog(@"B");
}

log

[Session started at 2009-11-07 20:46:10 +0900.]
2009-11-07 20:46:19.170 xxx[2374:207] A

What is the cause?

EDIT:

I tried. But it not executed.

-(void)sampleItemA:(NSString*)a itemB:(NSString*)b itemC:(NSDate*)c{
    NSLog(@"A");
    NSArray* ary = [[NSArray alloc] initWithObjects:a, b, c, nil];
    NSLog(@"%@", [ary description]);
    NSLog(@"B");
}

log

[Session started at 2009-11-07 21:25:37 +0900.]
2009-11-07 21:25:48.738 xxx[2455:207] A


It is generally unwise to pass nonconstant format strings into NSLog, things get wonky. Try:

-(void)sampleItemA:(NSString*)a itemB:(NSString*)b itemC:(NSDate*)c{
    NSLog(@"A");
    NSArray* ary = [[NSArray alloc] initWithObjects:a, b, c, nil];
    NSLog(@"%@", [ary description]);
    NSLog(@"B");
}


I change NSArray to NSMutableArray. It is executed.

-(void)sampleItemA:(NSString*)a itemB:(NSString*)b itemC:(NSDate*)c{
    NSLog(@"A");
    NSArray* ary = [[NSMutableArray alloc] init];
    [ary addObject:a];
    [ary addObject:b];
    [ary addObject:c];
    NSLog(@"%@", [ary description]);
    NSLog(@"B");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜