I have code that I inherited - and there is very liberal use of DispatchQueue.main.async because they were concerned the UI code there wasn't on the main thread - but it already was on the main queue.
The bug I saw, was that if the calling code was already on the main thread, and the function they called also called the DispatchQueue.main.async, it seems like that call was delayed/not-called, and being requeued on the run loop for the next call.
Here's kind of a general - very stripped down - version of what I was experiencing:
var result = 1
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
print("Before : result = \(self.result)")
self.doStuff()
print("After : result = \(self.result)")
}
}
func doStuff() {
self.result += 1
self.doStuff2()
}
func doStuff2() {
DispatchQueue.main.async {
self.result += 1
self.doStuff3()
}
}
func doStuff3() {
result += 1
}
}
The output is:
Before : result = 1
After : result = 2
So it enters doStuff2() but that function also calls DispatchQueue.main.async - and therefore, that code never gets executed.
I cleaned it up by removing these extraneous calls - but it took A LONG TIME tracking all of them down.
Is there any better way to debug this?
Also - they said this code worked in iOS 12.
Thanks,
Scott
Post
Replies
Boosts
Views
Activity
In a large project that I am working on, SwiftUI Previews do not work. (Xcode 13.4, iOS 15)
You can make the simplest of SwiftUI files - like:
import SwiftUI
struct TestView: View {
var body: some View {
Text("Hello, World!")
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
And the Canvas will only show:
"Automatic preview updating pauses when the previewed file is edited in a way that causes the containing module to be rebuilt."
I've tried Resume, Refresh Canvas, Deleting Derived Data - but we just can't seem to get it to work.
Any ideas?
Thanks in advance,
Scott
I'm working on an eCommerce app. And there's a label that has the SKU/Product number.
When I am testing with VoiceOver for "4LN99" the voice over reads back "4 Liters N ninety nine". I'd like it to read back "Four L N Nine Nine".
Is there a property to modify that?
iOS 16
Thanks,
Scott
I know "radio buttons" are not a standard iOS UI element, but this is what we have from our UX team.
They are technically UIButtons, but I don't feel it is correct to have the trait == .button.
Because if a user using VoiceOver taps it, and hears "Pickup, Button, Selected" - they might assume if they double tap on it, then, as a button, it should do something. But it won't do anything, because it is already selected. And since it is a Radio Button, it doesn't unselect when an action is applied.
There is no trait for "Radio Button".
Is trait .button the right way to go?
Thanks,
Scott
I prototyped using the UIDatePicker (in UIKit) for a designer. Out of the box, it works well without a lot of code:
The UI/UX designer was wondering if we could mimic how Apple's Calendar app displays the calendars:
Where the Inline calendar appears to expand into a cell filling the bounds.
I don't see how to control the frame or how the Calendar can be "told" where it is displayed?
Can this be done? (iOS 15+)
Thanks, Scott
I'm working on an app and want to include a Watch target.
My app uses Swift Package Manager and 1 package (that I created) for doing repetitive utilities such as showing a "Loading..." view (in iOS only)
The Swift Package Package has supported platforms set to:
platforms: [
.iOS(.v14)
]
However, when I try to start editing my Watch OS SwiftUI ContentView, the preview errors out stating:
iOS storyboards do not support target device type "watch". (This is from the Swift Package's Loading.storyboard.)
The Swift Package is UIKit only - no Swift UI. The "Loading..." view I am using for iOS is a View Controller - obviously not meant for Watch OS.
I cannot run the target to the Watch app - it shows a lot of UIKit errors from the Swift Package, like Cannot find type 'UIView' in scope and on and on.
The Watch app does not need this package at all.
I thought that if the platforms does not specify .watchOS* then it wouldn't try to apply it to my Watch target.
How do I tell this target not to link/load this package?
I just got my new Apple Watch series 9 - woo!
But I loaded a couple of my test apps onto it - and the complications are not rendering.
They work fine on my "old" series 6 (both are on WatchOS 10).
I tried resizing them. They run and render fine in the simulator.
But this is how it looks on my actual watch (the upper 2 complications are mine).
My guess is no... but, I have to ask.
I made a widget that checks our GitHub repository for new pull requests - in an attempt to make sure PRs are addressed quicker.
It works great - using GitHub's API. It's on my iPhone's Lock Screen. It definitely keeps me more on top of our pull requests!
Our product manager asked if we could also send a local notification when there's a new PR.
I was thinking maybe from the widget - it's updating around every 15 minutes - and if there's a new PR - then maybe it could fire a local notification.
However, there's the permissions. The user has to say "OK" to them. Widget can't do that. Can it inherit the notification permissions from the parent app?
Anyway - I think it is way overkill - I mean we have a widget! Why a notification as well!?!?!?
I thought I'd ask...
Thanks,
Scott
iOS 17.