Questions tagged [dispatch-queue]
231 questions
0
votes
2 answers
How do I re-use a block of code for a closure in Swift / Xcode 12.3
in my iOS app I am running a HKStatisticsCollectionQuery, which has an
query.initialResultsHandler = { query, results, error in [...] }
and a
query.statisticsUpdateHandler = { query, hkStats, results, error in [...] }
Both closures are exactly the…

Gin Tonyx
- 383
- 1
- 11
0
votes
1 answer
Swift Pulltorefresh on tableview what might be causing Thread 1: EXC_BAD_ACCESS (code=1, address=0x53178d8ac) from provided code
When recently testing my pull to refresh function on my homepageviewcontroller after about 10-30 pulls to refresh sometimes the controller crashes with Thread 1: EXC_BAD_ACCESS (code=1, address=0x53178d8ac)
Here is my code in my pull to refresh…

kuramura143
- 79
- 7
0
votes
1 answer
How to make another async call wait?
How to pause another async call if one of them catch a condition that need to be done first before continuing the other calls? From the code below (simplified), when makeRequest got 401, then it should call refreshSession and pause other calls until…

mrjimoy_05
- 3,452
- 9
- 58
- 95
0
votes
1 answer
Delegate method is not called on dispatch_async
I have a framework where I have to send the captured image back to the callee. So I have to wait for the delegate to finish
I am using dispatch_asyc to wait for the async operation of the delegate method.
But the delegate method is not called and…

Kuldeep Bhimte
- 961
- 1
- 10
- 25
0
votes
1 answer
How to run tasks in background thread sequentially
I have a data sync which should happen in a background thread in a sequential order as one task need to finish prior start syncing the next. I tried executing in a Dispatch queue. But then as the process scheduler decides what to execute first i ran…

danu
- 1,079
- 5
- 16
- 48
0
votes
1 answer
Swift: Rare crash on line that only says someDispatchQueue.sync {
Out of 6 testers, one user experiences a crash on a line that only says
someDispatchQueue.sync { //Thread 0 crash
someDispatchQueue cannot be nil because it is being declared as
let someDispatchQueue = DispatchQueue(label: "SomeDispatchQueue") at…

user2875404
- 3,048
- 3
- 25
- 47
0
votes
1 answer
Swift Load Website to Scrape Code Without Loading View | WebKit
I have an array of Google News article urls. Google News article urls redirect immediately to real urls, ie: CNBC.com/.... I am trying to pull out the real, redirected url. I thought I could loop through the list and load the Google News link in a…

Ryan
- 107
- 7
- 30
0
votes
1 answer
Swift Array Synchronization with DispatchQueue
If uploadFailed(for id: String), uploadSuccess() and updateOnStart(_ id: String) are called from the same thread (Thread 1 Main Thread) I understand that we wouldn't need a synchronized Queue. What if the the functions are called from different…

DesperateLearner
- 1,115
- 3
- 19
- 45
0
votes
2 answers
Having trouble using DispatchQueue to wait for data to return from Cloud Firestore in iOS app using Swift
I'm trying to use DispatchQueue to get my code to wait until a query retrieves the results I need from Cloud Firestore before it continues executing, but just haven't been able to get it to work. In the code below I am trying to get it to wait…

MarcE
- 69
- 8
0
votes
0 answers
Complete functions for item before moving to next item in array. iOS
I have a list of ids that I want to complete a set of functions for, each id is grabbed from an array and then a group of functions is called in the loop, I have a dispatch queue in the loop, but it seems to run through the loop too fast and before…

Tony Merritt
- 1,177
- 11
- 35
0
votes
1 answer
Swift -access UIApplication.shared.statusBarOrientation from main thread
I'm trying to access the UIApplication.shared.statusBarOrientation but I keep getting the error UIApplication.statusBarOrientation() must be used from main thread only:
I tried to add it and the switch statement that uses it to the mainQueue but…

Lance Samaria
- 17,576
- 18
- 108
- 256
0
votes
1 answer
How to disable all user interaction for NSApplication/NSWindow without blocking the main thread?
I have a Cocoa app that presents a folder structure to the user and allows basic file system operations such as move/copy/rename.
I perform all file system access on a background queue and use file coordination via NSFileCoordinator.
Let's imagine…

Mark
- 6,647
- 1
- 45
- 88
0
votes
0 answers
DispatchGroup waits forever
I have an async function with a completionHandler (let's say it's called asyncFunction) that I'm calling inside another function. I want this second function to wait for the async function. So, basically I want this second function to be run…

ataravati
- 8,891
- 9
- 57
- 89
0
votes
0 answers
Table View error on reloading sections - seems to be some race condition
I have some hard to solve crashes. They happen in application from time to time not in regular way. I think the problem maybe with some race conditions and synchronizations.
I am using such pattern.
1) reloadData()
2) reloadSection1(),…

Michał Ziobro
- 10,759
- 11
- 88
- 143
0
votes
1 answer
How to prevent Timing Problems When Using Closures?
I'm trying to find the sum of numbers, returned from different escaping closures. The sum to be returned in main thread.
import Foundation
var randomTime: Int {
return Int.random(in: 0...1000)
}
func first(completion: @escaping (Int) -> Void) {
…

ajitesh
- 23
- 4