grand-central-dispatch Questions
12
Solved
What is the new syntax for dispatch_once in Swift after the changes made in language version 3? The old version was as follows.
var token: dispatch_once_t = 0
func test() {
dispatch_once(&tok...
Whichsoever asked 17/6, 2016 at 17:16
10
Solved
I would like a for in loop to send off a bunch of network requests to firebase, then pass the data to a new view controller once the the method finishes executing. Here is my code:
var datesArray ...
Nassi asked 10/3, 2016 at 2:37
2
Solved
Could anyone help me to understand this code I created:
let cq = DispatchQueue(label: "downloadQueue", attributes: .concurrent)
cq.sync {
for i in 0..<10 {
sleep(2)
print(i)
}
}
pr...
Squash asked 23/2, 2022 at 8:45
4
When conforming to protocols or overriding superclass methods, you may not be able to change a method to be async, but you may still want to call some async code. For example, as I am rewriting a p...
Horne asked 11/6, 2021 at 20:31
7
Solved
How could I make my code wait until the task in DispatchQueue finishes? Does it need any completion handler or something?
func myFunction() {
var a: Int?
DispatchQueue.main.async {
var b: Int =...
Mclaren asked 27/2, 2017 at 11:9
2
Solved
I'm trying to set up an on boarding where I'm asking the user for a few permissions including: Location, Notifications and Camera. I have 3 different View Controllers set up, each asking for one of...
Longdrawnout asked 7/7, 2016 at 18:21
11
I have an UIView with an UIImageView subview. I need to load an image in the UIImageView without blocking the UI. The blocking call seems to be: UIImage imageNamed:. Here is what I thought solved t...
Oatmeal asked 4/10, 2013 at 10:37
1
I’m currently migrating my app to use the concurrency model in Swift. I want to serialize Tasks to make sure they are executed one after the other (no paralellism). In my use case, I want to listen...
Row asked 31/12, 2021 at 8:48
1
Solved
class SomeViewController: UIViewController {
let semaphore = DispatchSemaphore(value: 1)
deinit {
semaphore.signal() // just in case?
}
func someLongAsyncTask() {
semaphore.wait()
...
sem...
Hellenist asked 23/12, 2021 at 2:40
3
Solved
I have lot of experience with other programming languages, but not so much in swift 3. I want to do polling loop. This is what i have written:
DispatchQueue.global(qos: .userInitiated).async {
[u...
Madaih asked 5/6, 2017 at 11:32
6
Solved
I would assume that I am aware of how to work with DispatchGroup, for understanding the issue, I've tried:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoa...
Abutilon asked 19/4, 2018 at 14:38
1
Solved
I am following Stanfords' CS193p Developing Apps for iOS online course.
It is using the Grand Central Dispatch (GCD) API for a demo of multithreading.
But they noted, that
"GCD has been mostl...
Worms asked 21/11, 2021 at 17:10
4
Solved
Is there any good documention on how many threads are created by GCD?
At WWDC, they told us it's modeled around CPU cores. However, if I call this example:
for (int i=1; i<30000; i++) {
dispa...
Farmland asked 27/8, 2011 at 10:5
1
Solved
Let's say I have the following functions.
func first() async {
print("first")
}
func second() {
print("second")
}
func main() {
Task {
await first()
}
second()
}
main()...
Numidia asked 4/11, 2021 at 21:49
2
Solved
I have an existing debouncer utility using DispatchQueue. It accepts a closure and executes it before the time threshold is met. It can be used like this:
let limiter = Debouncer(limit: 5)
var valu...
Tab asked 31/10, 2021 at 14:31
9
Solved
I'm learning about concurrent programming for iOS. So far I've read about NSOperation/NSOperationQueue and GCD. What are the reasons for using NSOperationQueue over GCD and vice versa?
Sounds like...
Huonghupeh asked 29/4, 2012 at 15:24
6
Solved
I have a function that throws an error, in this function I have a inside a closure that I need to throw the error from it's completion handler. Is that possible ?
Here is my code so far.
enum Cal...
Tensimeter asked 19/10, 2015 at 11:53
1
Scenario
A simple SwiftUI App that consists of a TabView with two tabs. The App struct has a @StateObject property, which is being repeatedly and very quickly (30 times per second) updated by simul...
Eakin asked 20/7, 2021 at 6:20
3
Solved
Looking at the documentation for URLSession.dataTask it's clear this function is called asynchronously but there's no mention of whether the completionHandler returns to the main thread, the thread...
Littell asked 23/2, 2018 at 16:9
20
Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay: but with an argument like int/double/float?
Tensive asked 9/11, 2010 at 22:13
1
Solved
My intent is to understand the “cooperative thread pool” used by Swift 5.5’s async-await, and how task groups automatically constrain the degree of concurrency: Consider the following task group co...
Kamerman asked 14/6, 2021 at 22:50
5
Solved
I want to download some files, for example 100 files, at the same time. So I decided to add my download threads to a dispatch queue, and GCD will adjust how many threads will run at the same time.
...
Chemosh asked 18/9, 2015 at 2:12
26
Solved
I've gone through the iBook from Apple, and couldn't find any definition of it:
Can someone explain the structure of dispatch_after?
dispatch_after(<#when: dispatch_time_t#>, <#queue: di...
Hinckley asked 4/6, 2014 at 10:5
11
Solved
This is my issue. When my application enters background I want it to perform a function after certain period of time. This is what I do:
- (void)applicationDidEnterBackground:(UIApplication *)appl...
Grandpa asked 18/9, 2012 at 10:46
3
Solved
I'm using DispatchGroup.enter() and leave() to process a helper class's reverseG async function. Problem is clear, I'm using mainViewController's object to call mainViewControllers's dispatchGroup....
Dearly asked 6/8, 2017 at 17:38
© 2022 - 2024 — McMap. All rights reserved.