Questions tagged [dispatch-queue]
231 questions
1
vote
1 answer
Updating published variables using DispatchQueue.main.async in SwiftUI
I am working on a SwiftUI app that displays an AVCaptureVideoPreviewLayer and also implements the AVCaptureVideoDataOutputSampleBufferDelegate protocol to perform some custom logic in captureOutput(_: didOutput: from:). The custom logic was working…

John Harrington
- 1,314
- 12
- 36
1
vote
1 answer
DispatchQueue async issue
var numbers: [Int] = []
var queue = DispatchQueue(label: "myqueue", attributes: .concurrent)
DispatchQueue.concurrentPerform(iterations: 10) { i in
queue.async() {
print(i)
let last = numbers.last ?? 0
…

Bruce L
- 41
- 2
1
vote
1 answer
Swift asynchronous ConcurrentPerform
I have an asynchronous task that is repeated a few times to pull up various image URLs for some animals. The code goes something like this:
let animals = ['Cheetah', 'Lion', 'Elephant']
let image_urls: [String:[String]] = [:]
for animal in animals…

JoeVictor
- 1,806
- 1
- 17
- 38
1
vote
0 answers
Swift storyboard cross dissolve transition flashes different view controller
I am creating an app with cross dissolve transitions. The issue occurs when a view controller is presented and a previous screen flashes for a split second every time a cross dissolve transition happens until the app is forced closed and restarted.…

user16355394
- 21
- 4
1
vote
1 answer
DispatchQueue deadlock clarification needed
Look at these two slightly similar cases:
case 1:
func test() {
DispatchQueue.global().sync {
print("a")
DispatchQueue.main.sync {
print("b")
}
}
}
and
case 2:
func test() {
DispatchQueue.main.async {
print("a")
…

Romit Kumar
- 2,442
- 6
- 21
- 34
1
vote
2 answers
Perform action after picking image with async PHPicker
Problem
Want to perform operation BitwiseAND(UIImage1, UIImage2) this is function of OpenCV framework. UIImage1 is already presented in MainVC:
@IBOutlet weak var presentedImage: UIImageView!
So, UIImage2 must be picked additionally, whenever user…

Kacper Ducin
- 39
- 8
1
vote
0 answers
How to update UI after api call in didSelectShippingContact Apple Pay Swift
This is "didSelectShippingContact" function that calls when shipping address updates. I want api call in this function so i can get taxes. But the problem is if i don’t add delay here it is not updating apple pay ui. But i don't know how much delay…

Mustaqeez Ahmad
- 411
- 4
- 8
1
vote
1 answer
Alamofire how to maintain request order?
i am using a single serial queue as the rootQueue / request / serialization queue
let queue = DispatchQueue(label: "APIManager.rootQueue")
a.session = Session(configuration: sessionConfiguration,
delegate: a,
…

Peter Lapisu
- 19,915
- 16
- 123
- 179
1
vote
1 answer
Memory wont get cleared from background thread in Swift
I have an app that is constantly reading data from my server and updating the data in the UI. It pulls quite a bit of data, builds some data structures, and then passes the information to the UI. The code below shows how I am collecting the…

Quinn
- 7,072
- 7
- 39
- 61
1
vote
1 answer
How DispatchQueues are implemented under the hood?
I’m curious what DispatchQueue really is under the hood, I tried to google this information but all the documentation is rather abstract and doesn’t provide any real information about the implementation. In my understanding DispatchQueue is some…

starwarrior8809
- 361
- 1
- 10
1
vote
1 answer
Updating SwiftUI from HealthKit Query
I want to output the variable 'healthStore.valueTest' via ContentView in SwiftUI.
The class healtStore is structured as follows:
class HealthStore {
var healthStore: HKHealthStore?
var query: HKStatisticsQuery?
var valueTest:…

Jorge Reich
- 91
- 5
1
vote
1 answer
Core Data Count SwiftUI
When I add a new reminder to my list I can not see the count + 1 simultaneously. But when I re-run the program I see the count is correct.
https://vimeo.com/545025225
struct ListCell: View {
var list : CDListModel
@State var count = 0
…

Mert Köksal
- 817
- 1
- 7
- 26
1
vote
1 answer
Passing constants out of a function - Swift
I hope this doesn't sound dumb but I'm trying to put:
let lowercasedQuery = query.lowercased()
let usersNew = users.filter({ $0.fullname.lowercased().contains(lowercasedQuery) || $0.username.contains(lowercasedQuery)…

TheLegend27
- 25
- 6
1
vote
0 answers
How to stop DispatchGroup manually (When we reach a certain value) and get it to call .notify (finish all executions manually)
This is different than wanting to stop after a period of time.
An example of possible use case:
func calculate(_ nums: [Int], _ target: Int, completion: @escaping (([Int]) -> Void)) {
let enumerated = nums.enumerated()
let queue =…

shadow of arman
- 395
- 1
- 7
- 16
1
vote
1 answer
Does DispatchQueue also Lock the resources used inside it?
class Factory {
var localSharedResource
var localQueue = DispatchQueue(label: "localQueue")
let threadLock = NSLock()
func modify(){
localQueue.async {
self.threadLock.lock()
localSharedResource = "a change is made here"
…

George Termentzoglou
- 95
- 9