views:

50

answers:

3

I have this code

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]);

}

and right now they are all printed to the console instantly. How can I make a variable to decrease or increase the speed they are logged? I'm new at objective-C so thanks a lot for your help! :)

A: 

There's a sleepForTimeInterval: method on NSThread that might do what you're looking for. The documentation is here.

Edit: Sorry, for Objective-C newbies, you would just type something like this:

[NSThread sleepForTimeInterval:0.01];
Nick
A: 

See the sleep() function.

Chuck
A: 
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]);
}
igul222
thanks so much!!!!!
Pete