grand-central-dispatch

iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers

一曲冷凌霜 提交于 2021-02-06 03:48:11
问题 I have a singelton class which will be create in the app delegate. When i run XCTTests then its get create a second time. + (instancetype)urlSchemeManager { static dispatch_once_t onceToken; static UrlSchemeManager* _sharedInstance; dispatch_once(&onceToken, ^{ _sharedInstance = [UrlSchemeManager new]; }); return _sharedInstance; } This is resulting in two different instances. This was no problem if i just use it for unit test. But in the integration test, when i register an observer for

iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers

烂漫一生 提交于 2021-02-06 03:47:55
问题 I have a singelton class which will be create in the app delegate. When i run XCTTests then its get create a second time. + (instancetype)urlSchemeManager { static dispatch_once_t onceToken; static UrlSchemeManager* _sharedInstance; dispatch_once(&onceToken, ^{ _sharedInstance = [UrlSchemeManager new]; }); return _sharedInstance; } This is resulting in two different instances. This was no problem if i just use it for unit test. But in the integration test, when i register an observer for

iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers

邮差的信 提交于 2021-02-06 03:47:44
问题 I have a singelton class which will be create in the app delegate. When i run XCTTests then its get create a second time. + (instancetype)urlSchemeManager { static dispatch_once_t onceToken; static UrlSchemeManager* _sharedInstance; dispatch_once(&onceToken, ^{ _sharedInstance = [UrlSchemeManager new]; }); return _sharedInstance; } This is resulting in two different instances. This was no problem if i just use it for unit test. But in the integration test, when i register an observer for

iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers

北城以北 提交于 2021-02-06 03:47:22
问题 I have a singelton class which will be create in the app delegate. When i run XCTTests then its get create a second time. + (instancetype)urlSchemeManager { static dispatch_once_t onceToken; static UrlSchemeManager* _sharedInstance; dispatch_once(&onceToken, ^{ _sharedInstance = [UrlSchemeManager new]; }); return _sharedInstance; } This is resulting in two different instances. This was no problem if i just use it for unit test. But in the integration test, when i register an observer for

iOS Testing: dispatch_once get called twice. First in App, second in Test. Problems with Observers

风流意气都作罢 提交于 2021-02-06 03:47:12
问题 I have a singelton class which will be create in the app delegate. When i run XCTTests then its get create a second time. + (instancetype)urlSchemeManager { static dispatch_once_t onceToken; static UrlSchemeManager* _sharedInstance; dispatch_once(&onceToken, ^{ _sharedInstance = [UrlSchemeManager new]; }); return _sharedInstance; } This is resulting in two different instances. This was no problem if i just use it for unit test. But in the integration test, when i register an observer for

Use cocoa bindings and threads

末鹿安然 提交于 2021-01-29 11:23:48
问题 I have a few labels bound to a few variables that are modified in other threads via GCD. Now I've read that cocoa bindings are not thread safe but my app is running fine (the UI updates when the values of the variables are updated in a background thread) Would it be the correct way to do the calculations in the background thread and if I need to change the variable value make this via DispatchQueue.main.sync() { self.variable = newValue } ? If cocoa bindings are not thread safe, why I never

Dispatch group crashing because asynchronous function executes multiple time

流过昼夜 提交于 2021-01-29 04:30:43
问题 I am trying to use dispatch groups to wait for two asynchronous processes to finish. However the second asynchronous function loops to the amount of messages I have in my database. The code below crashes because the number of dispatch is not balanced since dispatch leave is higher than the number of dispatch enters due to the multiple executions of the second asynchronous function. Is there a different way to implement dispatch groups in this case. dispatch_group_enter(dispatch_group) ref

What happens if dispatch on same queue?

元气小坏坏 提交于 2021-01-29 03:34:12
问题 I'd like to understand for below case if it's needed to check whether callbackQueue is current queue. Please help me clear these scenarios, about what could happen if current queue is callback queue: callbackQueue is main queue. callbackQueue is concurrent queue. callbackQueue is serial queue. - (void)fetchWithCallbackQueue:(dispatch_queue_t)callbackQueue { dispatch_async(callbackQueue, ^{ }); } 回答1: I highly recommend you to watch these videos. Then go through the examples I provided and

How to use DispatchGroup to make asynchronous calls within a for loop

扶醉桌前 提交于 2021-01-27 18:52:01
问题 In my example code below, I call complete(false) on failure. However, since I'm using a DispatchGroup object to make sure all asynchronous requests are complete, I cannot just call syncGroup.leave() on failure, as the notify will be called, which contains complete(true) , making this function return true , when it should be returning false for failure. Am I correct in not calling syncGroup.leave() on failure to complete my function correctly? Or should I be calling syncGroup.leave() and

Why doesn't .async on a concurrent queue in a for loop behave the same as DispatchQueue.concurrentPerform?

半世苍凉 提交于 2021-01-07 02:55:00
问题 import Dispatch class SynchronizedArray<T> { private var array: [T] = [] private let accessQueue = DispatchQueue(label: "SynchronizedArrayAccess", attributes: .concurrent) var get: [T] { accessQueue.sync { array } } func append(newElement: T) { accessQueue.async(flags: .barrier) { self.array.append(newElement) } } } If I run the following code, 10,000 elements are appended to the array as expected even if I am reading concurrently: DispatchQueue.concurrentPerform(iterations: 10000) { i in _