Why does the picker pause other functions in the app?

So I am not a pro at swift or programming in general but I know most of the basics to it all. I am currently making a project for my Computer Science class and decided to use the "Picker View" in it, it took me a while to understand how to use the pickerData and Delegates, but once I figured it out, I found that after building, when I touch my Picker in the simulator, everything else pauses until the Picker is done moving. In my app, my timer is very important and can't have it pause when the picker is being used. Can someone please explain why this is happening?


class viewcontroller: UIPickerDataSource, UIPickerDelegate

IBOutlet weak var Lap: UIPickerView


func numberOfComponents(in pickerView: UIPickerView) -> Int {

return 1

}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

return pickerData.count

}

/

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {

return pickerData[row]

}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

Replies

You should run the other task in a different queue and let picker run in UI Queue (mainQueue).

I found that after building, when I touch my Picker in the simulator, everything else pauses until the Picker is done moving. In my app, my timer is very important and can't have it pause when the picker is being used. Can someone please explain why this is happening?

If, by “timer”, you mean Foundation’s

Timer
type, then it’s possible you could fix this by scheduling the timer in the common modes. See this post for more.

Claude31 wrote:

You should run the other task in a different queue …

This might be the right answer but it does introduce multithreading to your app, which may be more complexity then you need.

There’s a great variant of the “two problems” joke:

Some people, when confronted with a problem, think, “I know, I’ll use threads,” and then two they hav erpoblesms.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"