Search results for

swiftui

16,660 results found

Post

Replies

Boosts

Views

Activity

Picker style .menu doesn't handle nil
Here's the code... import SwiftUI enum Side: String { case left case right } struct SideView: View { @State private var name: String = @State private var side: Side? = nil var body: some View { NavigationStack { Form { Section { TextField(Name, text: $name) Picker(Side, selection: $side) { Text(Left).tag(Side.left as Side?) Text(Right).tag(Side.right as Side?) } .pickerStyle(.menu) // displays with Left selected even though side is nil // .pickerStyle(.inline) // all the other styles work as expected, nothing initially selected // .pickerStyle(.palette) // .pickerStyle(.navigationLink) } } } } } #Preview(SideView) { SideView() } Even though side is nil the .menu style displays with Left selected. Try any of the other styles. They all display with nothing initially selected. As they should when side is nil. This seems like a bug and I've submitted feedback. ID: FB21685273 Whether it's a bug or not has anyone worked around this?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
44
11h
SwiftUI/WKWebView app migrated from React Native to SwiftUI shows blank/blue screen for some users after App Store update
I’m hoping to get some insight from Apple engineers or developers who have seen similar behavior. Background We previously had a React Native / Expo iOS app in production for several years. Recently, we rebuilt the app completely from scratch as a native SwiftUI app using WKWebView (no shared code, no RN runtime). The new app architecture is: Native SwiftUI container WKWebView loading a remote web app Firebase Analytics & Crashlytics Push notifications (APNs + FCM) No local database, no persistent native state Migration scenario Users update the app via the App Store: Old app: React Native / Expo New app: native SwiftUI + WKWebView For most users, the migration works fine. However, for a about 10% of users, the following happens: The issue After updating from the old React Native app to the new SwiftUI app: The app opens The native landing screen appears (solid black OR blue background, depending on which most recent version if being installed) The app never transitions
Topic: UI Frameworks SubTopic: SwiftUI
0
0
45
19h
Reply to Image object detection with video sizing issue
Problem: Misaligned Vision Bounding Boxes in SwiftUI When using AVCaptureVideoPreviewLayer inside a UIViewRepresentable, my Vision bounding boxes were either stretched, offset to the side, or shrunken in the center. The standard GeometryReader approach failed because it reported the full screen dimensions, while the camera feed was being letterboxed or aspect-filled. The Solution: Native Layout Bridging I moved away from artificial scaling factors (like 1.33 or manual multipliers) and implemented a Pure Natural layout bridge. Capturing the Real Video Frame I added a closure (onLayout) to my UIView subclass. This allowed the UIKit layer to report its actual non-zero dimensions (e.g., 832×420) back to SwiftUI only after the layout math was finalized by the system. This eliminated the (0,0) size errors during initialization. Standardizing the Vision Request I set the VNImageCropAndScaleOption to .scaleFill. This ensures that the Vision coordinate system (0.0 to 1.0) maps exactly to the edges of
1d
Reply to SwiftUI .task does not update its references on view update
Attempting to follow your application and its current objective when tapping the button labeled that returns without incrementing the counter. However, the previous view does increment the counter, but that is not the button you are referring to. So this will always return without incrementing and that's the button you showing: guard current >= 0 else { continuation.finish() return } This is not the button pressed that does what you want: Button { id+=1 } label: { Text(update id by 1) } But just let me know what's the goal and I'm sure many developers may help you to provide you the swiftUI code you need. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
3d
SwiftUI .task does not update its references on view update
I have this sample code import SwiftUI struct ContentView: View { var body: some View { ParentView() } } struct ParentView: View { @State var id = 0 var body: some View { VStack { Button { id+=1 } label: { Text(update id by 1) } TestView(id: id) } } } struct TestView: View { var sequence = DoubleGenerator() let id: Int var body: some View { VStack { Button { sequence.next() } label: { Text(print next number).background(content: { Color.green }) } Text(current id is (id)) }.task { for await number in sequence.stream { print(next number is (number)) } } } } final class DoubleGenerator { private var current = 1 private let continuation: AsyncStream.Continuation let stream: AsyncStream init() { var cont: AsyncStream.Continuation! self.stream = AsyncStream { cont = $0 } self.continuation = cont } func next() { guard current >= 0 else { continuation.finish() return } continuation.yield(current) current &*= 2 } } the print statement is only ever executed if I don't click on the update id by 1 button.
1
0
146
3d
Performance Issues with ActionButton in MarketplaceKit – XPC Calls Causing UI Hangs
Hi all, I’m working on the alternative marketplace app and using MarketplaceKit and ActionButton. On the main page, users see a list of items, each with an ActionButton. I’m experiencing significant UI hangs when this page loads. What I’ve Observed: Instruments (Hangs and SwiftUI profilers) show that the hangs occur when ActionButton instances are rendered. Creating or updating ActionButton properties triggers synchronous XPC communication with the managedappdistributiond process on the main thread. Each XPC call takes about 2-3 ms, but with many ActionButtons, the cumulative delay is noticeable and impacts the user experience. I have tested on iOS 18.7 and 26.1, using Xcode 26.2. But in general, the issue is not specific to a device or iOS version. The problem occurs in both Debug and Release builds. Hangs can be severe depending on the number of items in a section, generally between 200-600 ms, resulting in noticeable lag and a poor user experience. I haven’t found much documentation on the interna
Topic: UI Frameworks SubTopic: SwiftUI
0
0
38
3d
Reply to NSHostingView stops receiving mouse events when layered above another NSHostingView (macOS Tahoe 26.2)
Thanks, but if you look at the demo code in my post: https://stackoverflow.com/questions/79862332/nshostingview-with-swiftui-gestures-not-receiving-mouse-events-behind-another-ns, I tried logging the hit tests for both the top and middle NSHostingViews. The logs confirm that clicks are reaching both views, but the middle layer’s button with the DragGesture still doesn’t respond. Do you know how your solution could be used here?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
3d
Reply to Animation does not work with List, while works with ScrollView + ForEach
@Claude31 so what should I do to fix it? Regarding your issue: https://stackoverflow.com/questions/74253108/why-is-animation-not-working-in-a-list-but-is-working-in-vstack This has nothing to do with my question. Also this is not true for me: // ❌ Not animating – it animates perfectly. Regarding https://stackoverflow.com/questions/76418666/swiftui-list-animations-are-not-smooth-when-adding-elements-to-a-vstack-in-a-lis : Adding .animation modifier did not help.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
3d
Reply to iOS and Android
I have two options that you should at least look at: If your goal is to run non-UI Swift code on Android then Swift’s Android Workgroup is making great strides on that front. If you want to extend that to SwiftUI code, there’s a third-party vendor who’s tackling that directly [1]. And to be clear, I’m not actually recommending either of these, because I’ll only recommend stuff that I’ve actually used. But you should at least factor them into your decision making. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com [1] https://skip.tools
Topic: Programming Languages SubTopic: Swift Tags:
3d
SwiftUI menu not resizing images
I failed to resize the icon image from instances of NSRunningApplication. I can only get 32×32 while I'm expecting 16×16. I felt it unintuitive in first minutes… Then I figured out that macOS menu seems not allowing many UI customizations (for stability?), especially in SwiftUI. What would be my best solution in SwiftUI? Must I write some boilerplate SwiftUI-AppKit bridging?
1
0
69
4d
WWDC21 Demystify SwiftUI question
When the guy was talking about structural identity, starting at about 8:53, he mentioned how the swiftui needs to guarantee that the two views can't swap places, and it does this by looking at the views type structure. It guarantees that the true view will always be an A, and the false view will always be a B. Not sure exactly what he means because views can't swap places like dogs. Why isn't just knowing that some View is shown in true, and another is shown in false, enough for its identity? e.g. The identity could be The view on true vs The view on false, same as his example with The dog on the left vs The dog on the right
0
0
46
4d
Reply to iOS and Android
Thanks for the great post. That's a common and excellent question for iOS developers looking to expand to Android and hope there are many Android developers in the forums wanting to provide their opinion how they manage the 2 different technologies. Looking forward to see other people’s opinions as mine is based on my development experience. I should be the last person to have an opinion about this based on my job. In my modest and personal opinion not being an Android developer, you will almost certainly need to rewrite the user interface of your app for Android. However, you might be able to reuse a significant portion of your app's core business logic, data models, and networking code written in Swift. iOS Uses UIKit (older) or SwiftUI (newer) for building UIs. Android uses XML layouts with Views (older) or Jetpack Compose (newer) for building UIs. As far as I know there's no direct way to convert SwiftUI or UIKit code into Android XML/Compose, or vice-versa. The underlying rendering engi
Topic: Programming Languages SubTopic: Swift Tags:
4d
Reply to Widget - App may push the list view twice when launched from widget
Thanks for the post. I’m trying to figure out if this is a bug report or there is something you are doing that causing that experience and I can help as tapping an app widget should indeed trigger a Universal Link only once, not twice . The observed behavior of it sometimes firing twice can lead to a poor user experience, causing duplicate actions, navigation, or data processing. The core issue is that the mechanism for opening the Universal Link from the widget, or the app's handling of that link, is being invoked more than once for a single user tap. Would you be able to provide me the app you are using as well as a link to your AASA file. If you're using a Link view in SwiftUI for your widget, ensure there isn't any accidental nesting or multiple Link instances covering the same tap area. Place a breakpoint or detailed logging at the delegate where the app gets called at. Is this method being called twice for a single widget tap? If your app uses SwiftUI's App lifecycle, check if the clos
4d