Show random string after shake in iOS via Swift -



Show random string after shake in iOS via Swift -

i observe shake motion via codes:

override func motionended(motion: uieventsubtype, withevent event: uievent) { if motion == .motionshake { self.shakelabel.text = "text" } } }

ok, working. need, when action shake motion, random item in 3 strings. cannot find solution.

prepare array of texts, , this:

let texts = ["text1", "text2", "text3"] self.shakelabel.text = texts[int(arc4random_uniform(uint32(texts.count)))]

after shake in 3 times, show random text

var shakecount = 0 allow shaketexts = ["text1", "text2", "text3"] override func motionended(motion: uieventsubtype, withevent event: uievent) { if motion == .motionshake { shakecount++ if shakecount >= 3 { self.shakelabel.text = shaketexts[int(arc4random_uniform(uint32(shaketexts.count)))] } } }

ios swift

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -