0

我有这个代码

NSArray *food = [NSArray arrayWithObjects:@"Apples:",@"bacon",@"corn",@"donuts",@"elfs",@"fidge",nil];

for(int i = 0; i<6; i++){
    NSLog(@"item at index %i is %@",i,[food objectAtIndex:i]);

}

现在它们都立即打印到控制台。我怎样才能使变量降低或提高他们记录的速度?我是 Objective-C 的新手,非常感谢您的帮助!:)

4

3 回答 3

3
NSArray *food = [NSArray arrayWithObjects:@"Apples:",@"bacon",@"corn",@"donuts",@"elfs",@"fidge",nil];

// the number of seconds to wait between printing each item
double secondsToSleep = 1.0;

for(int i = 0; i<6; i++){
    [NSThread sleepForTimeInterval:secondsToSleep];
    NSLog(@"item at index %i is %@",i,[food objectAtIndex:i]);
}
于 2010-07-07T03:01:39.873 回答
0

NSThread 上有一个 sleepForTimeInterval: 方法,它可能会满足您的需求。文档在这里

编辑:抱歉,对于 Objective-C 新手,您只需输入如下内容:

[NSThread sleepForTimeInterval:0.01];
于 2010-07-07T02:28:59.247 回答
0

sleep()功能。

于 2010-07-07T02:29:12.053 回答