Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

Posts under SwiftUI tag

200 Posts

Post

Replies

Boosts

Views

Activity

Camera Permissions Popup
We have a very strange issue that I am trying to solve or find the best practice for. We have a SwiftUI View that uses the Camera to preview. So as suggested in Apples Docs we check authorisation status and then if it's not determined we request authorisation. We also have the privacy entry in the info.plist case .notDetermined: AVCaptureDevice.requestAccess(for: .video) { accessStatusAuthorised in if !accessStatusAuthorised { self.cameraStatus = .notAuthorised } else { self.isAuthorized = true self.cameraStatus = .authorised self.startCameraSession(cameraPosition: cameraPosition) } } case .restricted: cameraStatus = .notAuthorised isAuthorized = false case .denied: cameraStatus = .notAuthorised isAuthorized = false case .authorized: cameraStatus = .authorised isAuthorized = true startCameraSession(cameraPosition: cameraPosition) break @unknown default: isAuthorized = true cameraStatus = .notAuthorised } However when we call this code it freezes the Camera feed, even when allow has been tapped. However and this is the confusing part. If we do not call the code above, we still get the permission for camera access pop up and the camera works fine after allowing. What im concerned about is changing the code to do this and its a possible apple bug that gets fixed and hey then none of the Apps allow the camera function. I cannot see any where that the process has changed for iOS 26 / Xcode 26. Can anyone shed any light on this or had similar experience ?
1
0
34
2d
Choppy minimized search bar animation
The new .searchToolbarBehavior(.minimized) modifier leads to a choppy animation both on device and SwiftUI canvas (iOS 26.2): I assume this is not the intended behaviour (reported under FB21572657), but since I almost never receive any feedback to my reports, I wanted to see also here, whether you experience the same, or perhaps I use the modifier incorrectly? struct SwiftUIView: View { @State var isSearchPresented: Bool = false @State var searchQuery: String = "" var body: some View { TabView { Tab { NavigationStack { ScrollView { Text(isSearchPresented.description) } .navigationTitle("Test") } .searchable(text: $searchQuery, isPresented: $isSearchPresented) .searchToolbarBehavior(.minimize) // **Choppy animation comes from here?** } label: { Label("Test", systemImage: "calendar") } Tab { Text("123") } label: { Label("123", systemImage: "globe") } } } } #Preview { if #available(iOS 26, *) { SwiftUIView() } else { // Fallback on earlier versions } }
4
0
299
2d
visionOS pushWindow being dismissed on app foreground
We seen to have found an issue when using the pushWindow action on visionOS. The issue occurs if the app is backgrounded then reopened by selecting the apps icon on the home screen. Any window that is opened via the pushWindow action is then dismissed. We've been able to replicate the issue in a small sample project. Replication steps Open app Open window via the push action Press the digital crown On the home screen select the apps icon again The pushed window will now be dismissed. There is a sample project linked here that shows off the issue, including a video of the bug in progress
3
1
691
4d
[SwiftUI][DragDrop][iPadOS] Drop into TabView Sidebar Tab not triggering. How to debug?
Are there tools to inspect why a drag-and-drop drop is not triggering in a SwiftUI app? I've declared .draggable on the dragging view, and .dropDestination on the receiving TabContent Tab view. This combination of modifiers is working on a smaller demo app that I have, but not on my more complex one. Is there a means to debug this in SwiftUI? I'd like to see if the drag-and-drop pasteboard actually has what I think it should have on it. Notably: "TabContent" has a far more restricted list of modifiers that can be used on it.
0
0
70
4d
UI Tests troubles with Xcode 26.1 and Xcode 26.2
Since I moved to Xcode 26.1 and Xcode 26.2 then, my UI tests all fail only for iOS 26+, for both simulator and real device. Everything worked perfectly with Xcode 26.0, and the code base of the application under test and the test cases are the same. With Xcode 26.0, the tests pass for iOS 26+ and iOS < 26, for both simulator and real device. In addition, even the Accessibility Inspector tool fails to display the view hierarchy for iOS 26+ with Xcode 26.2. With Xcode 26.0, whatever are the devices and the OS versions, the tool was able to display the view hierarchy. Otherwise the tool is empty even if the device and app are selected. This failing tests issue occurs both on my local environment and on GitHub Actions runners, excluding the hypothesis I have troubles with my own side. The error message for failing tests explains the element cannot be found anymore. Given for example the test case: @MainActor func testMakeScreenshotsForDocumentation_Button() { let app = launchApp() goToComponentsSheet(app) waitForButtonToAppear(withWording: "app_components_button_label", app) tapButton(withWording: "app_components_button_label", app) tapButton(withWording: "Strong", app) takeScreenshot(named: "component_button_", ACDC.buttonX, ACDC.buttonY, ACDC.buttonWidth, ACDC.buttonHeight, app) } the goToComponentSheet(app) line shows the error: ActionsDocumentationScreenshots.testMakeScreenshotsForDocumentation_Button() In details the function: /// Opens the page of the components, i.e. tap on the 2nd of the tab bar @MainActor func goToComponentsSheet(_ app: XCUIApplication) { app.tabBars.buttons.element(boundBy: 1).tap() } with the following error on the app.tabBars line: .../AppTestCase.swift:157 testMakeScreenshotsForDocumentation_Button(): Failed to tap Button (Element at index 1): No matches found for Descendants matching type TabBar from input {(Application, pid: 1883)} I have the feeling with Xcode 26.2 (and Xcode 26.1) the view hierarchy is not accessible anymore for both XCUITest framework and Accessibility Inspector tool. Note I have on my side macOS Tahoe 26.1 (25B78) and my GitHub Actions runner are on macOS 26.0.1 (25A362). When I used Xcode 26.0 I was on macOS Tahoe 26.1 (25B78) . Any ideas? 🙂
2
0
147
4d
Pickers in toolbar expand its width
With iOS 26 there has been a change in behavior with Pickers in the toolbar. The Picker looks expanded unlike other views such as a Button and Menu. See screenshots below. Is this the intended behavior or a bug? (I already submitted a feedback for this at FB19276474) What Picker looks like in the toolbar: What Button looks like in the toolbar:
1
0
92
5d
interactive glassEffect bug?
Applying glass effect, providing a shape isn't resulting in the provided shape rendering the interaction correctly. .glassEffect(.regular.tint(Color(event.calendar.cgColor)).interactive(), in: .rect(cornerRadius: 20)) results in properly drawn view but interactive part of it is off. light and shimmer appear as a capsule within the rect.
3
12
322
5d
iOS 26 NavigationStack Title Rendering Issue
Is anyone else experiencing NavigationStack title disappearing in iOS 26? Hey everyone, I just updated to iOS 26 and I'm running into a really frustrating issue with my app. Wondering if anyone else is seeing this or if I'm missing something obvious. What's happening: My navigation titles are completely blank when the app first loads, but then magically appear when I scroll down. It's super weird and makes my app look broken at first glance. My setup: I'm using NavigationStack with some pretty standard stuff: Navigation title with .navigationTitle() A toolbar with a settings button ScrollView content with a gradient background Here's basically what I have: NavigationStack { ScrollView { VStack(spacing: 24) { // My app content here - cards, etc. ForEach(myItems) { item in // Content cards } } .padding() } .background( LinearGradient( gradient: Gradient(colors: [ Color.surfacePrimary, Color.surfacePrimary.opacity(0.95), Color.surfaceSecondary.opacity(0.3) ]), startPoint: .top, endPoint: .bottom ) ) .navigationTitle("My Title") // ← This doesn't show up initially! .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Settings") { // Settings action } } } } The weird part: Works perfectly fine on my iOS 18.6.2 device Completely broken on iOS 26 - blank navigation area As soon as I scroll, the title appears and stays there Happens on both simulator and physical device What I've tried: Double-checking my code (it's identical to what worked before) Testing on multiple devices Different navigation title strings Removing and re-adding the toolbar Has anyone else run into this? I'm thinking it might be an iOS 26 bug with NavigationStack, but I wanted to check if others are seeing it before filing a radar. It's affecting my main landing screens (Tennis, NFL, and Prediction Markets tabs) and honestly looks pretty bad when users first open the app and see blank headers. Temporary fix I found: If anyone else hits this, I discovered that forcing inline titles works as a workaround: .navigationTitle("My Title") .navigationBarTitleDisplayMode(.inline) // This fixes it but kills large titles Obviously not ideal since we lose the nice large title behavior, but at least the titles show up. Questions: Is this happening to anyone else's iOS 26 apps? Any better workarounds that preserve large titles? Should I file this as a radar or is Apple already aware? Really hoping this gets fixed soon - having to choose between broken navigation or losing large titles is pretty frustrating. Thanks for any insights! Anyone else dealing with this NavigationStack nightmare in iOS 26? 😅
4
2
297
6d
Question about submission.
Hello all! My name is Luke, and I'm a 14 year old with a idea for SSC. This is my first SSC submission ever. I would like some feedback concerning a question. My app is an AI powered academic planner that helps you and your life. It uses a mini on-device LLM to help organize assignments. This is a real business I am building, and I put inside of my app simulated features such as the app saying "scanning your Google Classroom..", would this go against any terms and make the app less likely to win? I also have my app fully polished, and feels like an actual app and finished product, with demo assignments pre-loaded, and most stuff is placeholders. Should the app be more like a guided simulator? Such as "click here to see how this will be simulated in a final release" or again should it be polished? I just want some feedback, since I only have 3 minutes, and the app needs to be offline, I just want to improvise. You can check out the basis of my app at my website. https://whiteb0x.me Hopefully I can get some feedback from the community, and/or ex winners! Thanks all! - Luke
1
0
65
6d
Control Widget SF image cannot stably display
I'm working on the control widget which should display the SF image on the UI, but I have found that it cannot be displayed stably. I have three ExampleControlWidget which is about the type egA egB and egC, it should all be showed but now they only show the text and placeholder. I'm aware of the images should be SF image and I can see them to show perfectly sometimes, but in other time it is just failed. This's really confused me, can anyone help me out? public enum ControlWidgetType: Sendable { case egA case egB case egC public var imageName: String { switch self { case .egA: return "egA" case .egB: return "egB" case .egC: return "egC" } } } struct ExampleControlWidget: ControlWidget { var body: some ControlWidgetConfiguration { AppIntentControlConfiguration( kind: kind, provider: Provider() ) { example in ControlWidgetToggle( example.name, isOn: example.state.isOn, action: ExampleControlWidgetIntent(id: example.id), valueLabel: { isOn in ExampleControlWidgetView( statusText: isOn ? Localization.on.text : Localization.off.text, bundle: bundle, widgetType: .egA //or .egB .egC ) .symbolEffect(.pulse) } ) .disabled(example.state.isDisabled) } .promptsForUserConfiguration() } } public struct ExampleControlWidgetView: View { private let statusText: String private let bundle: Bundle private var widgetType: ControlWidgetType = .egA public init(statusText: String, bundle: Bundle, widgetType: ControlWidgetType) { self.statusText = statusText self.bundle = bundle self.widgetType = widgetType } public var body: some View { Label( statusText, image: .init( name: widgetType.imageName, // the SF Symbol image id bundled in the Widget extension bundle: bundle ) ) } } This is the normal display: These are the display that do not show properly: The results has no rules at all, I have tried to completely uninstall the APP and reinstall but the result is same.
3
0
327
6d
iOS18 Control Widget custom symbol preview failed
i export apple SF as custom sf for test. code is simple: var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind:"ControlWidgetConfiguration" ) { ControlWidgetButton(action: DynamicWidgetIntent()) { Text("test") Image("custom_like") } }.displayName("test") } as we can see, it can't show image in the preview. but it can show image in the Control widget center. am i do some thing wrong?
5
7
1k
6d
How to correctly move a TextField selection cursor when inserting UTF16 text
I'm trying to implement a feature whereby a user can tap a button to insert a character at the cursor in a TextField - the cursor then needs to be moved forward to be in front of the insert character. I'm having trouble with characters such as π which are UTF16 encoded. In the following sample app, enter the following sequence: Enter 9 by keyboard tap + Enter 9 by keyboard tap π Enter 9 via keyboard tap + he TextField will show '9+9π+9' (i.e. the final + is inserted before 9 rather than after it. Any insight into what I am doing wrong? import SwiftUI @main struct TextInsertApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var text: String = "" @State private var selection: TextSelection? = nil var body: some View { TextField("", text: $text, selection: $selection) .background(.gray.opacity(0.4)) Button("+") { insert("+") } Button("π") { insert("π") } } func insert(_ insertString: String) { if let selection { if case let .selection(range) = selection.indices { if selection.isInsertion { text.insert(contentsOf: insertString, at: range.lowerBound) } else { text.replaceSubrange(range, with: insertString) } let cursor = text.utf16.index(range.upperBound, offsetBy: insertString.count) self.selection = .init(insertionPoint: cursor) } } else { text += insertString selection = .init(range: text.utf16.endIndex..<text.utf16.endIndex) } } }
1
0
156
1w
Text with Liquid Glass effect
I'm looking for a way to implement Liquid Glass effect in a Text, and I have issues. If I want to do gradient effect in a Text, no problem, like below. Text("Liquid Glass") .font(Font.system(size: 30, weight: .bold)) .multilineTextAlignment(.center) .foregroundStyle( LinearGradient( colors: [.blue, .mint, .green], startPoint: .leading, endPoint: .trailing ) ) But I cannot make sure that I can apply the .glassEffect with .mask or .foregroundStyle. The Glass type and Shape type argument looks like not compatible with the Text shape itself. Any solution to do this effect on Text ? Thanks in advance for your answers.
2
0
358
1w
BUG: Toolbar Rendering Bug -- ToolbarItem Duplication when Back Button Hidden
To whom it may concern that deals with bugs in SwiftUI for iOS 26: Inadvertently discovered a bug which duplicates ToolbarItem in any placement in the toolbar when navigationBarBackButtonHidden is set to true. .toolbar{ ToolbarItem(placement: .confirmationAction) { Button("Stop", systemImage: "stop.fill"){ //some action } } } .navigationBarBackButtonHidden(true) Expected Behavior Show the ToolbarItem Actual Behavior Duplicates items in the placement position. Thank you.
1
0
123
1w
Using @Environment with TabView
Let me ask the general question first, then explain the context... Each Tab of a TabView defines a separate View hierarchy. (I'm assuming that the root view of each Tab defines its own NavigationStack.) Since an @Environment is supposed to serve data to the child views in its view hierarchy, does this mean that it is possible to define Environments in each tab's root view with the same name (i.e. key) but different values? (I.e., I want a subview to access an environment value for the current view hierarchy without requiring that the subview have any knowledge of which hierarchy it is being called from.) The actual use case has to do with using @Environment in a tabbed application to inject a router in subviews. (Each Tab has its own NavigationStack and its own NavigationPath.) I have an @Observable router class which manages a NavigationPath.. The root view of each Tab in the application has its own instance of that router object (and hence, it's own NavigationPath). I want to inject that router into all of the subviews in each Tab's view hierarchy, so that I can use path-based navigation. My current implementation injects the router throughout the view hierarchies via constructor injection. This works, but is a real pain and includes a bunch of duplicate code. I would like to use @Environment injection instead, but this can only work if @Environment stores its EnvironmentValues on a per view-hierarchy (rather than a per-application) basis. So, can this approach work? what experience can you share concerting router-based navigation in a TabView-based app? Thanks.
2
0
156
1w
Sheet keeps dismissing as soon as text focus
Anytime I launch a view that contains a textfield, as soon as it’s in focus the view dismisses, and I log this warning, I have tried everything I could think of and still no solution, anyone know a workaround to this? note: this happens both on simulator and physical devices -[rtiinputsystemclient remotetextinputsessionwithid:performinputoperation:] perform input operation requires a valid sessionid. input modality = keyboard, input operation = , custom infotype = uiemojisearchoperations
1
0
93
1w
Keyframe animation crashes with +[_SwiftUILayerDelegate _screen]: unrecognized selector sent to class on iOS 26
We have an UIViewController called InfoPlayerViewController. Its main subview is from a child view controller backed by SwiftUI via UIHostingController. The InfoPlayerViewController conforms to UIViewControllerTransitioningDelegate. The animation controller for dismissing is DismissPlayerAnimationController. It runs UIKit keyframe animations via UIViewPropertyAnimator. When the keyframe animation is executed there’s an occasional crash for end users in production. It only happens on iOS 26. FB Radar: FB20871547 An example crash is below. Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Reason: +[_SwiftUILayerDelegate _screen]: unrecognized selector sent to class 0x20c95da08 Termination Reason: SIGNAL 6 Abort trap: 6 Triggered by Thread: 0 Last Exception Backtrace: 0 CoreFoundation 0x1a23828c8 __exceptionPreprocess + 164 (NSException.m:249) 1 libobjc.A.dylib 0x19f2f97c4 objc_exception_throw + 88 (objc-exception.mm:356) 2 CoreFoundation 0x1a241e6cc +[NSObject(NSObject) doesNotRecognizeSelector:] + 364 (NSObject.m:158) 3 CoreFoundation 0x1a22ff4f8 ___forwarding___ + 1472 (NSForwarding.m:3616) 4 CoreFoundation 0x1a23073a0 _CF_forwarding_prep_0 + 96 (:-1) 5 UIKitCore 0x1a948e880 __35-[UIViewKeyframeAnimationState pop]_block_invoke + 300 (UIView.m:2973) 6 CoreFoundation 0x1a22cb170 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSDictionaryHelpers.m:10) 7 CoreFoundation 0x1a245d7cc -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 288 (NSDictionaryM.m:271) 8 UIKitCore 0x1a948e6bc -[UIViewKeyframeAnimationState pop] + 376 (UIView.m:2955) 9 UIKitCore 0x1a7bc40e8 +[UIViewAnimationState popAnimationState] + 60 (UIView.m:1250) 10 UIKitCore 0x1a94acc44 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 684 (UIView.m:17669) 11 UIKitCore 0x1a94ae334 +[UIView(UIViewKeyframeAnimations) animateKeyframesWithDuration:delay:options:animations:completion:] + 224 (UIView.m:17945) 12 MyApp 0x102c78dec static UIView.animateNestedKeyframe(withRelativeStartTime:relativeDuration:animations:) + 208 (UIView+AnimateNestedKeyframe.swift:10) 13 MyApp 0x102aef3c0 closure #1 in DismissPlayerAnimationController.slideDownBelowTabBarTransitionAnimator(using:) + 156 (DismissPlayerAnimationController.swift:229) 14 MyApp 0x102a2d3d4 <deduplicated_symbol> + 28 15 UIKitCore 0x1a7d5ae5c -[UIViewPropertyAnimator _runAnimations] + 172 (UIViewPropertyAnimator.m:2123) 16 UIKitCore 0x1a83e1594 __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke_3 + 92 (UIViewPropertyAnimator.m:3557) 17 UIKitCore 0x1a83e1464 __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke + 96 (UIViewPropertyAnimator.m:3547) 18 UIKitCore 0x1a83e1518 __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke_2 + 144 (UIViewPropertyAnimator.m:3553) 19 UIKitCore 0x1a83e0e64 -[UIViewPropertyAnimator _setupAnimationTracking:] + 100 (UIViewPropertyAnimator.m:3510) 20 UIKitCore 0x1a83e1264 -[UIViewPropertyAnimator startAnimationAsPaused:] + 728 (UIViewPropertyAnimator.m:3610) 21 UIKitCore 0x1a83de42c -[UIViewPropertyAnimator pauseAnimation] + 68 (UIViewPropertyAnimator.m:2753) 22 UIKitCore 0x1a87d5328 -[UIPercentDrivenInteractiveTransition _startInterruptibleTransition:] + 244 (UIViewControllerTransitioning.m:982) 23 UIKitCore 0x1a87d5514 -[UIPercentDrivenInteractiveTransition startInteractiveTransition:] + 184 (UIViewControllerTransitioning.m:1012) 24 UIKitCore 0x1a7c7931c ___UIViewControllerTransitioningRunCustomTransitionWithRequest_block_invoke_3 + 152 (UIViewControllerTransitioning.m:1579) 25 UIKitCore 0x1a892aefc +[UIKeyboardSceneDelegate _pinInputViewsForKeyboardSceneDelegate:onBehalfOfResponder:duringBlock:] + 96 (UIKeyboardSceneDelegate.m:3518) 26 UIKitCore 0x1a7c79238 ___UIViewControllerTransitioningRunCustomTransitionWithRequest_block_invoke_2 + 236 (UIViewControllerTransitioning.m:1571) 27 UIKitCore 0x1a94ab4b8 +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:animated:] + 188 (UIView.m:17089) 28 UIKitCore 0x1a7c79070 _UIViewControllerTransitioningRunCustomTransitionWithRequest + 556 (UIViewControllerTransitioning.m:1560) 29 UIKitCore 0x1a86cb7cc __77-[UIPresentationController runTransitionForCurrentStateAnimated:handoffData:]_block_invoke_3 + 1784 (UIPresentationController.m:1504) 30 UIKitCore 0x1a7c43888 -[_UIAfterCACommitBlock run] + 72 (_UIAfterCACommitQueue.m:137) 31 UIKitCore 0x1a7c437c0 -[_UIAfterCACommitQueue flush] + 168 (_UIAfterCACommitQueue.m:228) 32 UIKitCore 0x1a7c436d0 _runAfterCACommitDeferredBlocks + 260 (UIApplication.m:3297) 33 UIKitCore 0x1a7c43c34 _cleanUpAfterCAFlushAndRunDeferredBlocks + 80 (UIApplication.m:3275) 34 UIKitCore 0x1a7c1f104 _UIApplicationFlushCATransaction + 72 (UIApplication.m:3338) 35 UIKitCore 0x1a7c1f024 __setupUpdateSequence_block_invoke_2 + 352 (_UIUpdateScheduler.m:1634) 36 UIKitCore 0x1a7c2cee8 _UIUpdateSequenceRunNext + 128 (_UIUpdateSequence.mm:189) 37 UIKitCore 0x1a7c2c378 schedulerStepScheduledMainSectionContinue + 60 (_UIUpdateScheduler.m:1185) 38 UpdateCycle 0x28c58f5f8 UC::DriverCore::continueProcessing() + 84 (UCDriver.cc:288) 39 CoreFoundation 0x1a2323230 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:2021) 40 CoreFoundation 0x1a23231a4 __CFRunLoopDoSource0 + 172 (CFRunLoop.c:2065) 41 CoreFoundation 0x1a2300c6c __CFRunLoopDoSources0 + 232 (CFRunLoop.c:2102) 42 CoreFoundation 0x1a22d68b0 __CFRunLoopRun + 820 (CFRunLoop.c:2983) 43 CoreFoundation 0x1a22d5c44 _CFRunLoopRunSpecificWithOptions + 532 (CFRunLoop.c:3462) 44 GraphicsServices 0x2416a2498 GSEventRunModal + 120 (GSEvent.c:2049) 45 UIKitCore 0x1a7c50ddc -[UIApplication _run] + 792 (UIApplication.m:3899) 46 UIKitCore 0x1a7bf5b0c UIApplicationMain + 336 (UIApplication.m:5574) // ...
4
1
475
1w