2010-07-07 26 views
0

我有這樣的代碼更改數組循環的速度? Objective-C的

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,非常感謝您的幫助! :)

+0

我不明白,你想減慢循環?你可以在每個週期之間入睡。但爲什麼? – 2010-07-07 02:21:30

+0

是啊,我怎麼能在每個週期之間睡覺?我也想改變它會睡多久。 – Pete 2010-07-07 02:23:10

+1

你真的想解決什麼問題? – 2010-07-07 02:30:39

回答

0

在NSThread上有一個sleepForTimeInterval方法可以做你想要的。該文檔是here

編輯:對不起,Objective-C的新手,你只需要輸入這樣的事情:

[NSThread sleepForTimeInterval:0.01]; 
+0

我試着用這種技術進度條,它似乎先睡覺然後執行循環,所以它真的不會變慢。 – Miek 2011-11-02 18:20:57

0

sleep()功能。

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]); 
} 
+0

非常感謝!!!!! – Pete 2010-07-07 03:38:49