grand-central-dispatch

wait for two asynchronous completion functions to finish, before executing next line code

对着背影说爱祢 提交于 2021-02-18 03:40:50
问题 I have two functions: func Females_NonChat() and func males_NonChat() I want to wait for both of them to finish before executing the print statement in viewdidload. Do I need another completion handler to accomplish that? Those functions used are firebase completion handlers for requesting information from the online database... override func viewDidLoad() { super.viewDidLoad() func Females_NonChat() func males_NonChat() print("finished executing both asynchronous functions") } func Females

How to correctly display a “progress” sheet modally while using Grand Central Dispatch to process something?

不羁岁月 提交于 2021-02-15 11:45:44
问题 I'm trying to display a sheet on a window containing a single progress bar, to show the progress of some long function running asynchronously using Grand Central Dispatch. I've almost got it, but can't get the sheet to appear to be in focus, probably because I haven't used runModalForWindow: or similar. This is approximately what I'm doing at the moment, it happens as a result of a button press on the main window: // Prepare sheet and show it... [NSApp beginSheet:progressSheet modalForWindow

How to correctly display a “progress” sheet modally while using Grand Central Dispatch to process something?

我的梦境 提交于 2021-02-15 11:45:32
问题 I'm trying to display a sheet on a window containing a single progress bar, to show the progress of some long function running asynchronously using Grand Central Dispatch. I've almost got it, but can't get the sheet to appear to be in focus, probably because I haven't used runModalForWindow: or similar. This is approximately what I'm doing at the moment, it happens as a result of a button press on the main window: // Prepare sheet and show it... [NSApp beginSheet:progressSheet modalForWindow

How to correctly display a “progress” sheet modally while using Grand Central Dispatch to process something?

牧云@^-^@ 提交于 2021-02-15 11:41:12
问题 I'm trying to display a sheet on a window containing a single progress bar, to show the progress of some long function running asynchronously using Grand Central Dispatch. I've almost got it, but can't get the sheet to appear to be in focus, probably because I haven't used runModalForWindow: or similar. This is approximately what I'm doing at the moment, it happens as a result of a button press on the main window: // Prepare sheet and show it... [NSApp beginSheet:progressSheet modalForWindow

Using delay DispatchQueue in “for in loop”

别来无恙 提交于 2021-02-11 14:08:29
问题 The task is to change the background color once a second. Was used "for in loop". For delay, a DispatchQueue was used. Everything seems to be fine, but it was noticed that after 10 iterations, the background color begins to change with a delay of 2 seconds, a little later in 3 seconds. The more iterations, the greater the delay. I displayed time in the console (seconds) to see how it changes. I see the results, but I do not understand what is wrong. I did the task through a timer, there were

Confused about Operation and OperationQueue QoS relationship

不想你离开。 提交于 2021-02-11 06:29:35
问题 The OperationQueue documentation states for the qualityOfService property: This property specifies the service level applied to operation objects added to the queue However one can simply check that this is not true by just copy & pasting the code below into a new playground. import Foundation let q = OperationQueue() q.qualityOfService = .userInitiated print("QUEUE", q.qualityOfService.rawValue) let op = BlockOperation() op.addExecutionBlock { print("OP", op.qualityOfService.rawValue) } q

Using Dispatch.main in code called from XCTestCase does not work

 ̄綄美尐妖づ 提交于 2021-02-08 08:35:38
问题 I have a function that is a async wrapper around a synchronous function. The synchronous function is like: class Foo { class func bar() -> [Int] { return [1,2,3] } class func asyncBar(completion: @escaping ([Int]) -> Void) { DispatchQueue.global(qos: .userInitiated).async { let intArray = bar() DispatchQueue.main.async { completion(intArray) } } } } When I call it from a XCTestCase completion does not run. Is there some sort of perverse interaction between the way unit tests are done in XCode

SwiftUI updating UI with high frequency data

▼魔方 西西 提交于 2021-02-08 06:51:30
问题 I'm trying to update the main view with high frequency data coming from separate background thread. I've created two tabviews and in case of slow update rate I can change the view. But in another case the UI doesn't react. I've observed this behavior only on real device, in the simulator works everything fine. The while loop is still representing an imu, just to keep it simple. Did someone any idea how to fix this issue? Many thanks! import SwiftUI struct ContentView: View {

SwiftUI updating UI with high frequency data

守給你的承諾、 提交于 2021-02-08 06:51:21
问题 I'm trying to update the main view with high frequency data coming from separate background thread. I've created two tabviews and in case of slow update rate I can change the view. But in another case the UI doesn't react. I've observed this behavior only on real device, in the simulator works everything fine. The while loop is still representing an imu, just to keep it simple. Did someone any idea how to fix this issue? Many thanks! import SwiftUI struct ContentView: View {

How to efficiently read thousands of small files with GCD

£可爱£侵袭症+ 提交于 2021-02-07 05:41:26
问题 I'd like to read some metadata data (e.x.: EXIF data) from potentially thousands of files as efficiently as possible without impacting the user experience. I'm interested if anyone has any thoughts on how best to go about this using something like regular GCD queues, dispatch_io channels or even another implementation. Option #1: Using regular GCD queues. This one is pretty straightforward I can just use something like the following: for (NSURL *URL in URLS) { dispatch_async(dispatch_get