Questions tagged [dispatch-queue]

231 questions
1
vote
1 answer

DispatchQueue Barrier Not Working As Expected

I have this code in playground import PlaygroundSupport import Foundation PlaygroundPage.current.needsIndefiniteExecution = true let queue = DispatchQueue(label: "Barrier Test", attributes: .concurrent) func syncProcess(index: Int) { …
1
vote
1 answer

How to load image from Firebase into users avatar

I have a problem with loading images from firebase. I have two functions. One of them collect info about user, second one load users avatar image. Unfortunately images load after function creates new user. I know it will be problem with asynchronous…
Jan Duda
  • 39
  • 5
1
vote
1 answer

sync a group of async functions

I have some functions to async to each other so, they starts same time but they also sync to others, I built that structure but it looks so dirty, I wanted to ask maybe there is another way to do this. func doCalc() { let x = 100 let y =…
1
vote
1 answer

DispatchQueue doesn't behave like serial queue

By using following code, I am expecting that every time the func is caled, minimum time between executions will be 3-4 seconds. But: when I call the writeData() 4 times in row, I see that async block executed without waiting for previous call…
Vitaliy A
  • 3,651
  • 1
  • 32
  • 34
1
vote
0 answers

Swift UI Queues and DispatchQueue.main.async

I'm currently building a game in Swift that overlays a 'd-pad' and various other items such as a score label and start label on the game itself. Those items are set up in an SCNView, while the game itself, consisting of a ship and tunnel, is built…
1
vote
1 answer

Decoding a Dictionary Inside a Dictionary - JSON/Swift

I have a JSON file that is structured like this: "forecast": [ { "altimeter": "", "clouds": [ { "repr": "OVC025", "type": "OVC", "altitude": 25, "modifier": null, "direction":…
1
vote
1 answer

Closure argument passed as @noescape to Objective-C has escaped

I'm trying to use a resource wrapper for a thread safe access. In my implementation, awaitedValue field performs a synchronous read of resource through a serial queue. For some reason, whenever I try to read this property, my app crashes with an…
EBDOKUM
  • 1,696
  • 3
  • 15
  • 33
1
vote
1 answer

How to publish changes from the background thread Swift UI GET Request

I have set up my app such that I use UserDefaults to store a users login info (isLoggedIn, account settings). If a user is logged in and exits out of the application, and then relaunches the app, I would like them to be returned to the home page…
msoni
  • 25
  • 1
  • 5
1
vote
1 answer

Proper use of DispatchQueue in swift login

Im not using properly DispatchQueue function since I have to click 2-3 times in order to change screen, since the data dont load on time. I tried couple of positions in the code but Im always getting the same result. What is a proper use? Here is…
1
vote
0 answers

How to hide label in viewModel with DispatchQueue

I have an issue, and got stuck. Don't know how to solve this. There is a camera and some masks. When I open the camera and scroll to choose one of the masks, I want to show explanation how to use the camera with the masks, and these explanations…
Jkrist
  • 748
  • 1
  • 6
  • 24
1
vote
1 answer

stop dispatchquene().async in loop globally using swift

override func viewDidLoad() { super.viewDidLoad() worktask = DispatchWorkItem { for i in 1…4 { sleep(2) DispatchQueue.main.async { …
1
vote
2 answers

Beginner question on DispatchQueue.main.async

In MainViewController, in viewDidLoad() I'm calling a function which in turn tests if Auth.auth().currentUser == nil; If the condition is met then the statement to execute presents another view controller. In the if statement, why does the…
1
vote
0 answers

how to handle URLSession.shared.dataTask properly

Hi developers im having some issue or misplaced tasks so i had to develop a framework with some functions this is my main FUNCTION where the issue began     func saveDataDevice(idPos: String, macAddress: String) {         // this first function…
ZeroCooL
  • 79
  • 5
1
vote
0 answers

How to make a serial queue of tasks running in main thread with asynchronous callbacks?

In this case I have to consider the asynchronous callback as part of the task. I want only one task running at the same time. Here is boilerplate: func queueATask() { DispatchQueue.main.async { doSomeHeavyWorkPartA() …
Li Fumin
  • 1,383
  • 2
  • 15
  • 31
1
vote
1 answer

How to pass a block of type dispatch_block_t to a method

In the below code, I am trying to pass a block of type dispatch_block_t to dispatch_async as shown below. I have tried the following: dispatch_async(defaultPriority, block1(2, 3000)); dispatch_async(defaultPriority, (^block1)(2,…