Questions tagged [dispatch-queue]

231 questions
0
votes
2 answers

iOS Swift Timer in not firing if the App is in the background

I am developing a Cocoapod library in which, i have to Call a function when timer fires. I am using that Cocoapod in an iOS App, Timer is not firing when App goes to background state private var timer : DispatchSourceTimer? = nil let queue =…
Gokul
  • 97
  • 1
  • 11
0
votes
1 answer

Error with Dispatch Queue Swift

I am trying to create a genetic algorithm for running race cars around a race track. Each car gets random instructions that apply a force to the car and rotate the car by a certain number of degrees. In order to space out the new instructions given…
Bushers
  • 5
  • 4
0
votes
2 answers

dispatchqueue using in asynchronously to speedup in Swift 4

I have an old iOS application developed with Swift 1.2. In that used dispatch queues for speed up runtime. dispatch_async(dispatch_get_main_queue()) { } In Swift 4 I have tried by changing like below DispatchQueue.main.async { [weak self] in …
user8769899
0
votes
1 answer

How to load contact image in background?

I'm developing an app using Contact Book. I am displaying the call history from API and when I display the history-data, I check if the contact is available in the contact book or not. If it is available then I display the contacts name and image. I…
0
votes
1 answer

Swift 4: Access Variables from DispatchQueue.main (Scope)

I have a CoreML Image Classification task, that takes the "live stream" from the iOS device's [video] camera and occurs in the background. Once objects have been been identified, and other app logic has occurred, I would like to update the UI's…
jingo_man
  • 509
  • 3
  • 13
0
votes
1 answer

How both sync and async work with thread safe?

In Swift, we can leverage DispatchQueue to prevent race condition. By using serial queue, all things are performed in order, from…
onmyway133
  • 45,645
  • 31
  • 257
  • 263
-1
votes
2 answers

When can I run a synchronous code by executing DispatchQueue.main.sync { }?

I tried running the following code and it raises the following error every time: DispatchQueue.main.sync { } Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) I found this post on stackoverflow that says to never run synchronous…
daniel
  • 1,446
  • 3
  • 29
  • 65
-1
votes
1 answer

SwiftUI toasts not Dismissing

I am using the following method to display a toast message DispatchQueue.main.async { Toastmessage = MyToasts(title: "Message Here" , type: .success) mysettings.showMytoast = true // mysettings is an Environment variable } Reason I added like this…
Ae Ri
  • 185
  • 1
  • 12
-1
votes
2 answers

How to move to the next view upon data reception?

I am struggling to trigger the logic responsible for changing the view at the right time. Let me explain. I have a view model that contains a function called createNewUserVM(). This function triggers another function named requestNewUser() which…
PeterUI
  • 61
  • 4
-1
votes
1 answer

Swift: returned result is repeated using DispatchQueue.global (qos: .userInitiated) .asyncAfter

I have the following code: ( Inside: ServerApiManager.sharedInstance.fetchMessages is a function for call api ). The result returned is: ====didRequestReloadThread ATC Chat…
-1
votes
2 answers

Resetting DispatchQueue each time a tap occurs

I have a simple app that is intended to work like this: App loads with a default image Once a tap is received a random image is loaded from list If no tap is received for 5 seconds we reset back to default image I'm attempting to accomplish this…
-1
votes
1 answer

Multithreading - DispatchQueue asyncAfter delay in Swift

I am using the following code to invoke a function periodically every second. The problem is delay is actually 1.1 seconds and gets drifted more and more eventually as can be seen in NSLogs (and it is visible in other parts of the code as well apart…
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
-1
votes
1 answer

Better way of using "self." in background thread?

After adding DispatchQueue.global(qos: .background).async {} to a single function of my code (Xcode 10, Swift 5), the scrollbar looks like this: These are more than 40 calls to vars and other funcs that need a "self.". Fixing this isn't hard…
Neph
  • 1,823
  • 2
  • 31
  • 69
-1
votes
2 answers

Firebase query not executing in the correct order?

I fetch data and display in a tableView, the problem is the data is not executing in the correct order. I have tried: for case let child as DataSnapshot in data!.children.reversed() { let newDispatchGroup =…
user11182243
-1
votes
1 answer

How to run tasks on one thread only?

Say I have several database write closures and I want to execute them on a single thread, but not as a batch - I need to update UI after each write. Serial queues like: DispatchQueue.global(qos: .background).async {} or DispatchQueue(label: "hello…
Ivan
  • 1,320
  • 16
  • 26
1 2 3
15
16