Post

Replies

Boosts

Views

Activity

Reply to Dispatch Queue - main and in background situation with var
You have to think of the order of execution, when you use asynchronous patterns. The order of execution here is:a. Line 3b. Line 5, which causes line 7-12 to be executed "later", continuing on for "now" with…c. lines 15-23d. (later) lines 7-12What you'll need to do, basically, is move lines 15-23 inside a closure that's dispatch back to a background queue/thread after the stuff on th main thread is done.
Feb ’20
Reply to DispatchQueue Help
This isn't the way to do it. For a start, what you've done is more or less exactly the same as executing the code in the closure on the main thread, simply: self.functionA() self.functionB()Dispatching them asynchronously just delays the start of functionA slightly, and nothing else.Presumably, functionA actually has some asynchonous effect of its own. If it didn't it would do all its works synchronously, which would block the main thread, and you'd be raising that issue instead. So, currently, you're starting functionB after functionA has begun its work, but not finished. That means functionB has no data to work with, and so does nothing. (There's some guesswork in all of that, so the details might not be right).Therefore, I'm guessing, what you really want is to start functionB after functionA's incomplete work has actually finished. For that, you need an asynchronous pattern, where (for example) functionA takes a completion handler closure, which it executes it when its work is done: self.functionA(completionHandler: { self.functionB() })or, a bit more attractively, with trailing closure syntax: self.functionA { self.functionB() }Again, I'm guessing at things you didn't give any details on, but an asynchronous pattern sounds like the sort of thing you need.
Feb ’20
Reply to catch performSegue(withIdentifier)
It throws an Obj-C exception (NSException), which is a kind of app crash, not a Swift exception, which is a kind of error.You can't handle NSExceptions in Swift, and (current best practice) you shouldn't try. It's generally correct to let the app crash. Note that segue identifiers are static in a storyboard, so it shouldn't be necessary to test for the existence of a segue at run time.
Jan ’20