简体   繁体   中英

How stop another function from an UIButton function using Swift?

I got two functions running called updatePrice and updateTime, and I want to stop them when I click an UIButton.

func updateTime() {...}
func updatePrice() {...}

// ..

@IBAction func Button(sender: UIButton) { 

    // What should I write here? 

}

Do something like NSOperation s do: make a boolean and periodically check it in those functions. Something like:

var stopFuncs = false

and later in functions at sensitive moments insert that:

if stopFuncs { return }

and add this to button code:

stopFuncs = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM