ios - Dispatch and Delay between calls -
i'm making clone old game simon (a.k.a. genius, in brazil), 1 coloured buttons player needs press following sequence of colors. for testing, interface has 4 coloured buttons created array button outlets, easy access: var buttonarray:[uibutton] = [self.greenbutton, self.yellowbutton, self.redbutton, self.bluebutton] also, created array store sequence of colors var colors:[int] = [] when game starts calls function adds random number 0 3 (index on buttonarray), , add number colors array after adding new color color sequence, app needs show sequence user, can repeat it for that, calls playmoves function, uses loop run through colors array , change alpha button, simulating 'blink' func playmoves(){ let delay = 0.5 * double(nsec_per_sec) let time = dispatch_time(dispatch_time_now, int64(delay)) in self.colors{ self.buttonarray[i].alpha = 0.2 dispatch_after(time, dispatch_get_main_queue(), { self.buttona...