Questions tagged [ios-multithreading]
59 questions
2
votes
1 answer
How to ensure calls are done serially in swift3 app using GCD
I need this block of code to run in order:
UIApplication.shared.beginIgnoringInteractionEvents()
loadDataTask.resume()
UIApplication.shared.endIgnoringInteractionEvents()
It's being run inside of DispatchQueue.main.async() (every network call is…

Lucas Earl
- 395
- 1
- 3
- 13
2
votes
2 answers
dispatch_barrier_async seems no effect on the global queue?
when I am try the GCD function dispatch_barrier_async, it worked as expected on queue created by dispatch_queue_create, while when I put it on the global queue created by dispatch_get_global_queue, the barrier seems not work any more = =, somebody…

MichaelMao
- 528
- 6
- 15
2
votes
1 answer
Run two instance of the same app - split view
Didn’t have my hand on the iPad air or the iPad Pro. Would it be possible to run two instance of the same app in the two split views?

shebelaw
- 3,992
- 6
- 35
- 48
1
vote
0 answers
Swift. Execute a code in original thread when runing inside other thread
I have the iOS app i am coding with SwiftUI . And part of the code is from Kotlin multiplatform (kmm)
I need to do some work with async code, it must be executed in separate Thread.
But also i have callbacks to run during the Thread execution and…

Roman Doubush
- 21
- 2
1
vote
1 answer
`sleep(_:)` vs `asyncAfter(deadline:execute:)`
I have a value type for which a relatively long calculation is require to produce it (> 1s). I wrap this value type in an enumeration that expresses whether it is currently being calculated or is available:
enum Calculatable {
case…

shoe
- 952
- 1
- 20
- 44
1
vote
1 answer
how do I capture a property in thread-safe way
My class A has a property of class B which can be reset:
class A1 {
private var b = B(0)
func changeB(i : Int) {
b = B(i)
}
func testB(k : Int) -> Bool {
return b.test(k)
}
}
class B {
private let b :…

Alex Cohn
- 56,089
- 9
- 113
- 307
1
vote
2 answers
weakSelf not _always_ needed in iOS and ObjC, right?
Help me resolve a tiny argument with a colleague. Weak self is not needed in this circumstance, right?
(He doesn't believe me)
__weak auto weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf _someHelper];
});

h.and.h
- 690
- 1
- 8
- 26
1
vote
0 answers
Inconsistent state from Realm on a background thread in Swift
Despite using autoreleasepool and instantiating a new realm instance on each access of realm, I sometimes get inconsistent state.
In the following (contrived) example there is only one MyObject stored in the database. After the delete, the second…

vin047
- 260
- 3
- 12
1
vote
1 answer
How to utilize multiple processor cores in iOS to achieve the fastest/shortest computation of a loop accessing shared data?
When running a for-loop over an array in Swift running on iOS, I'd like to utilize the entire CPU for I feel that this should in theory speed up the computation. However my result is the opposite, that in running everything on a single DispatchQueue…

Justin Ganzer
- 582
- 4
- 15
1
vote
2 answers
Returning from threading/ GCD/ completion handler
I have some logic to sign a user in from a login screen. If the login fails, I want to display a message to let the user know. If the user logs in successfully, I trigger a segue. When I test it with invalid credentials, the error alert displays as…

user7804097
- 308
- 1
- 3
- 17
1
vote
1 answer
Multiple Async APIs to populate uitableview in desired order iOS swift
I have multiple API calls that will update the uitableview whenever they fetch the results.
UI needs to be updated as and when API gives the data. All API calls are async.
The data must be populated in the right order. API0 should update section 0,…

Ishan Baboota
- 23
- 5
1
vote
0 answers
Retrieving HealthKit data on main thread is causing the app crash for random users - iOS - Swift
I'm using HealthKit on my app to read user's health data and show them the data in the appropriate place on my app. For some production users(Major impact is on an iPhone X user), It's getting crashed while retrieving the health data using…

Ashok
- 5,585
- 5
- 52
- 80
1
vote
2 answers
Why private queue dispatch _async update UI after main queue update UI?
The ideal way to update UI using background thread is
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
…

GAURAV JAIN
- 37
- 5
1
vote
0 answers
performSelector queue & runloop schedule
I have read apple's code example ListAdder about how to use NSOperation. Technical Note TN2109 also explains the details.
If there is already an Operation calculating, and the user delete a data by remove a cell from the tableview, then the…

blueGhost
- 13
- 5
1
vote
1 answer
How to wait for completion handler inside a @synchronized block?
I want to call a completion handler synchronously inside a critical section (using @synchronized block). I am trying to wait for completion handler using semaphore, but the semaphore signal is never called.
Here is what I am doing:
NSNumber *lock =…

coder_andy
- 376
- 1
- 3
- 17