Search code examples
objective-cdelaynstimer

Objective c time delay


Here is my code so far:

- (IBAction) startApproximiteLevel:(id)sender {
[getBackgroundLevel startAnimation:self];
float sample1;
float sample2;
float sample3;
float sample4;
float sample5;
float finalSample;

float charlieSoundVolume = [charlieSoundLevel floatValue];

sample1 = charlieSoundVolume;
sleep(1)
sample2 = charlieSoundVolume;
sleep(1)
sample3 = charlieSoundVolume;
sleep(1)
sample4 = charlieSoundVolume;
sleep(1)
sample5 = charlieSoundVolume;
sleep(1);
finalSample = ((sample1 + sample2 + sample3 + sample4 + sample5) / 5);
self.backgroundSoundChange.floatValue = finalSample;

[getBackgroundLevel stopAnimation:self];

}

But this will stop another part of my code from updating the charlieSoundLevel. Any idea on how to do this without the sleep()?

Elijah


Solution

  • Look at [NSObject performSelector: withObject: afterDelay:] to launch a method on the run loop after a certain amount of time.