Search results for

“swiftui”

17,492 results found

Post

Replies

Boosts

Views

Activity

Reply to NSTextAttachment view flicker while typing in same paragraph
Thanks for posting. I built a minimal test to try to reproduce this — a SwiftUI NSViewRepresentable-wrapped NSTextView with a custom NSTextAttachment subclass and a viewProvider returning a custom NSView. I then stress-tested it against five plausible causes, and none of them reproduced any flicker: Baseline pattern — custom attachment + view provider returning a tinted layer-backed view, type in the same paragraph as the inserted attachment: stable. No caching in loadView() — every call constructs a brand-new NSView with fresh subviews and constraints: stable. Aggressive layout invalidation on every keystroke — NSTextLayoutManager.invalidateLayout(for: documentRange) from a textDidChange: delegate: stable. Mixed content sources — both attachment.image set to a programmatically drawn NSImage and a custom viewProvider returning a separate NSView: stable. Raster image content — loadView() returns an NSView containing an NSImageView with a real NSBitmapImageRep-backed NSImage instead of a layer-tinted p
Topic: UI Frameworks SubTopic: AppKit
May ’26
Reply to Programatically adding to a TextField and moving the TextSelection point in SwiftUI
Thanks for the focused reproducer and the video — they made this easy to investigate. There are two separate problems in what you're seeing, and the right answer is to switch to a different SwiftUI API for this kind of programmatic text editing. The bug in your code: String.Index invalidation after replaceSubrange RangeReplaceableCollection.replaceSubrange(_:with:) invalidates all indices into the collection (per the documentation), not just indices at or after the modified range. In your code: self.text.replaceSubrange(from..
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to SwiftUI retain cycle with .searchable
@hydrudcatt3 Thanks for the post. The thread is 4 years old, I think will be a great idea if you could post a new thread with all the details of the issue and the code you have posted. Is what you experiencing like SwiftUI's implementation of .searchable sometimes holds onto the Binding longer than the view's lifecycle? Is that what you are seeing? Looking forward to see your new post with all the details. Albert
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to Glass effect interactive effect issue when used with concentric shapes
Thanks for the post. So interesting and there are many SwiftUI people that are probably going to jump into the thread. In my case I wanted to test the use .clear.interactive(), SwiftUI generates a visual highlight layer that responds to user touches. To optimize this highlight animation, the system tries to resolve the shape provided in the in: parameter into a standard primitive. Because .concentric corners are dynamic, the interaction highlight engine currently fails to resolve the exact bezier path for the mask? In this case manifests as a highly rounded rectangle. Sometimes the interaction engine needs an explicit contentShape to properly map the hit-testing and highlight bounds, rather than relying solely on the in: parameter of the glass effect. struct ContentView: View { var body: some View { VStack { Text(Hello, World!) .frame(maxWidth: .infinity, maxHeight: .infinity) .glassEffect(.clear.interactive(), in: .rect(cornerRadius: 32)) .padding(36) .ignoresSafeArea() .preferredColorSchem
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’26
Reply to RealityView AR - anchored to the screen not the floor
// // ARUserAuth.swift // XRSandbox // // Created by Andy Wyatt on 3/15/26. // import SwiftUI import RealityKit import ARKit import AVFoundation import CoreMotion public struct ARUserAuth { public static var isAvailableAndAuthorizedByUser: Bool { guard ARWorldTrackingConfiguration.isSupported else { return false } return hasCameraAuthorization && hasMotionAuthorization } public static var hasCameraAuthorization: Bool { let authStatus = AVCaptureDevice.authorizationStatus(for: .video) if authStatus == .notDetermined { requestUserAuthorizationForCamera() } return authStatus == .authorized } public static func requestUserAuthorizationForCamera() { print(ARUserAuth: Camera access not determined, requesting user authorization) AVCaptureDevice.requestAccess(for: .video) { granted in if granted { print(ARUserAuth: App access to Camera authorized by user) // since these are modal popups, request Motion & Fitness only after Camera access granted if coreMotionAuthorizationStatus == .notDetermined {
Topic: Graphics & Games SubTopic: RealityKit Tags:
May ’26
Reply to RealityView AR - anchored to the screen not the floor
FYI: // // ContentView.swift // XRSandbox // // Created by Andy Wyatt on 3/15/26. // import SwiftUI import RealityKit struct ContentView: View { private let rootEntity = Entity() var body: some View { RealityView { content in content.add(rootEntity) } update: { content in updateARState(&content) } .ignoresSafeArea() .onAppear() { configureVirtualCamera() rootEntity.addChild(makeThing()) } .onTapGesture { spinThing() } .overlay { overlayView } } //MARK: - overlay with toggles at bottom @State private var arToggleState: Bool = false @State private var showARView: Bool = false @State private var perspectiveCameraInAR: Bool = false private var overlayView: some View { VStack { Spacer() VStack { Toggle(Enable AR, isOn: $arToggleState) .onChange(of: arToggleState) { handleARToggle() } // If PerspectiveCamera is in the RealityView entity heirarchy // the content is anchored to the screen rather than the floor Toggle(Keep PerspectiveCamera in AR, isOn: $perspectiveCameraInAR) .disabled(arToggleState) //
Topic: Graphics & Games SubTopic: RealityKit Tags:
May ’26
Glass effect interactive effect issue when used with concentric shapes
Using .glassEffect(.clear.interactive(), in: shape), where shape is some concentric shape that adapts to corner radius of the device, results in appearing of highlighted capsule shape. Code to reproduce this behavior import SwiftUI struct HelloLiquidGlass: View { var body: some View { if #available(iOS 26.0, *) { Text(Hello, World!) .frame(maxWidth: .infinity, maxHeight: .infinity) // .glassEffect(.clear.interactive(), in: .rect(corners: .concentric)) // .glassEffect(.clear.interactive(), in: ConcentricRectangle(uniformTopCorners: .fixed(80))) .padding(36) .ignoresSafeArea() .preferredColorScheme(.dark) } } } #Preview { HelloLiquidGlass() } Either of both commented-out modifiers produces the same result when user interacts with Liquid Glass pane (revealing of capsule shape that is not relative to actual shape of liquid glass effect modifier) iOS 26.5 (23F73) SDK + iOS 26.5 (23F77) Simulator
3
0
458
May ’26
Reply to How do I dismiss a presented sheet?
Hi @coastalDev On visionOS, sheets don't dismiss when you tap outside them — that's a deliberate platform behavior, and SwiftUI doesn't expose a modifier to opt into iPadOS-style tap-outside dismissal. The Human Interface Guidelines describe a sheet on visionOS (along with macOS, tvOS, and watchOS) as always modal, meaning people can't interact with the parent view until they explicitly dismiss it. This also matches how system presentations behave on visionOS — .alert, .confirmationDialog, .fileImporter, .photosPicker, and the share sheet are all dismissed via an explicit control rather than a tap outside. Following the same pattern in your custom sheet will feel native. For a data-entry Form like yours, consider pairing a Cancel button with a Done (or Save) button as text buttons in the sheet's toolbar, as many system apps do. The Best practices section of the HIG codifies this pairing — The Cancel (or Close) button dismisses a sheet without saving any changes… The Done button dismisses a sheet afte
May ’26
SwiftUI template in Instruments 26.4.1 shows empty channels on iOS 26.4.2 device — even with a minimal TimelineView repro
Hi all, I've hit a reproducible issue where the presence of the SwiftUI instrument in a template prevents any data from being recorded, including from the other instruments in the same template. Removing the SwiftUI instrument immediately restores normal recording. Environment Host: macOS 26.4.1 (25E253), Mac mini Xcode / Instruments 26.4.1 (17E202) Device: iPhone 17, iOS 26.4.2 (23E261) (physical device, USB-attached) Symptom Recording the same app, same device, same session, only varying the template contents: SwiftUI template (as-is) => All lanes empty across the entire recording Same template with the SwiftUI instrument removed => Data collected normally (Time Profiler samples, Hangs, etc.) So it seems not an issue with the SwiftUI lanes specifically being empty — including the SwiftUI instrument appears to silence the entire recording. Steps to reproduce Open Instruments → pick the SwiftUI template (or build a custom template that inclu
3
0
1.3k
May ’26
My new thing I made
FirstByte: Code-Core is a floating developer HUD for iPad that helps decode technical acronyms, coding terminology, and infrastructure concepts in real time. Designed for developers, students, operators, and AI-assisted workflows, the app features draggable transparent overlays, flip-card explanations, customizable themes, adjustable transparency, and a compact non-intrusive interface built for multitasking. Perfect for GitHub workflows, Web3 tooling, cloud infrastructure, SwiftUI development, and learning complex technical stacks without breaking focus.
0
0
801
May ’26
Workarounds for Xcode previews errors: Cannot preview in this file - Failed to Launch
I have started to have issues with SwiftUI previews of iOS apps with projects under the Documents folder. I have experimented that in Xcode 26.4 and I am still seeing it in 26.5. The error is: Cannot preview in this file. Failed to launch xyz.abc.TestApp Looking at the diagnostics, Xcode gets a permission denied error when trying to open /Users/me/Documents/path/to/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o Error details below. Note that I have set DerivedData folders relative to the projects' roots. Additional information: I get errors on freshly created iOS projects, just trying to preview the default ContentView. Xcode has full disk access set in System Preferences > Privacy & Security. I have cleaned build folders, deleted the simulators, Xcode itself, cleared various caches, restarted and reinstalled Xcode to no avail. Checking Editor > Canvas > Use Legacy Preview
4
0
522
May ’26
Overlay window above all windows, even when moving spaces
Hi! I would like to overlay a macOS application window above all windows, even when moving spaces or moving to a fullscreen app, similar in function to the DropOver app for macOS. What I have tried: Overwriting the default app delegate in SwiftUI and creating the NSWindow myself. Then setting the window.collectionBehavior to [.canJoinAllApplications, .canJoinAllSpaces, .fullScreenAuxiliary] and the window.level to .floating or .statusBar. This works for moving between Spaces, but still does not display above apps in fullscreen mode. I also registered a notification observer for NSWorkspace.activeSpaceDidChangeNotification, where I call window.orderFrontRegardless() to always have my window frontmost. Still not displaying above fullscreen apps. What am I missing to make this work? Best regards
2
0
694
May ’26
Reply to NSTextAttachment view flicker while typing in same paragraph
Thanks for posting. I built a minimal test to try to reproduce this — a SwiftUI NSViewRepresentable-wrapped NSTextView with a custom NSTextAttachment subclass and a viewProvider returning a custom NSView. I then stress-tested it against five plausible causes, and none of them reproduced any flicker: Baseline pattern — custom attachment + view provider returning a tinted layer-backed view, type in the same paragraph as the inserted attachment: stable. No caching in loadView() — every call constructs a brand-new NSView with fresh subviews and constraints: stable. Aggressive layout invalidation on every keystroke — NSTextLayoutManager.invalidateLayout(for: documentRange) from a textDidChange: delegate: stable. Mixed content sources — both attachment.image set to a programmatically drawn NSImage and a custom viewProvider returning a separate NSView: stable. Raster image content — loadView() returns an NSView containing an NSImageView with a real NSBitmapImageRep-backed NSImage instead of a layer-tinted p
Topic: UI Frameworks SubTopic: AppKit
Replies
Boosts
Views
Activity
May ’26
Reply to Programatically adding to a TextField and moving the TextSelection point in SwiftUI
Thanks for the focused reproducer and the video — they made this easy to investigate. There are two separate problems in what you're seeing, and the right answer is to switch to a different SwiftUI API for this kind of programmatic text editing. The bug in your code: String.Index invalidation after replaceSubrange RangeReplaceableCollection.replaceSubrange(_:with:) invalidates all indices into the collection (per the documentation), not just indices at or after the modified range. In your code: self.text.replaceSubrange(from..
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to SwiftUI retain cycle with .searchable
@hydrudcatt3 Thanks for the post. The thread is 4 years old, I think will be a great idea if you could post a new thread with all the details of the issue and the code you have posted. Is what you experiencing like SwiftUI's implementation of .searchable sometimes holds onto the Binding longer than the view's lifecycle? Is that what you are seeing? Looking forward to see your new post with all the details. Albert
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to Glass effect interactive effect issue when used with concentric shapes
Thanks for the post. So interesting and there are many SwiftUI people that are probably going to jump into the thread. In my case I wanted to test the use .clear.interactive(), SwiftUI generates a visual highlight layer that responds to user touches. To optimize this highlight animation, the system tries to resolve the shape provided in the in: parameter into a standard primitive. Because .concentric corners are dynamic, the interaction highlight engine currently fails to resolve the exact bezier path for the mask? In this case manifests as a highly rounded rectangle. Sometimes the interaction engine needs an explicit contentShape to properly map the hit-testing and highlight bounds, rather than relying solely on the in: parameter of the glass effect. struct ContentView: View { var body: some View { VStack { Text(Hello, World!) .frame(maxWidth: .infinity, maxHeight: .infinity) .glassEffect(.clear.interactive(), in: .rect(cornerRadius: 32)) .padding(36) .ignoresSafeArea() .preferredColorSchem
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to RealityView AR - anchored to the screen not the floor
// // ARUserAuth.swift // XRSandbox // // Created by Andy Wyatt on 3/15/26. // import SwiftUI import RealityKit import ARKit import AVFoundation import CoreMotion public struct ARUserAuth { public static var isAvailableAndAuthorizedByUser: Bool { guard ARWorldTrackingConfiguration.isSupported else { return false } return hasCameraAuthorization && hasMotionAuthorization } public static var hasCameraAuthorization: Bool { let authStatus = AVCaptureDevice.authorizationStatus(for: .video) if authStatus == .notDetermined { requestUserAuthorizationForCamera() } return authStatus == .authorized } public static func requestUserAuthorizationForCamera() { print(ARUserAuth: Camera access not determined, requesting user authorization) AVCaptureDevice.requestAccess(for: .video) { granted in if granted { print(ARUserAuth: App access to Camera authorized by user) // since these are modal popups, request Motion & Fitness only after Camera access granted if coreMotionAuthorizationStatus == .notDetermined {
Topic: Graphics & Games SubTopic: RealityKit Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to RealityView AR - anchored to the screen not the floor
// // XRSandboxApp.swift // XRSandbox // // Created by Andy Wyatt on 3/6/26. // import SwiftUI @main struct XRSandboxApp: App { var body: some Scene { WindowGroup { ContentView() } } }
Topic: Graphics & Games SubTopic: RealityKit Tags:
Replies
Boosts
Views
Activity
May ’26
Reply to RealityView AR - anchored to the screen not the floor
FYI: // // ContentView.swift // XRSandbox // // Created by Andy Wyatt on 3/15/26. // import SwiftUI import RealityKit struct ContentView: View { private let rootEntity = Entity() var body: some View { RealityView { content in content.add(rootEntity) } update: { content in updateARState(&content) } .ignoresSafeArea() .onAppear() { configureVirtualCamera() rootEntity.addChild(makeThing()) } .onTapGesture { spinThing() } .overlay { overlayView } } //MARK: - overlay with toggles at bottom @State private var arToggleState: Bool = false @State private var showARView: Bool = false @State private var perspectiveCameraInAR: Bool = false private var overlayView: some View { VStack { Spacer() VStack { Toggle(Enable AR, isOn: $arToggleState) .onChange(of: arToggleState) { handleARToggle() } // If PerspectiveCamera is in the RealityView entity heirarchy // the content is anchored to the screen rather than the floor Toggle(Keep PerspectiveCamera in AR, isOn: $perspectiveCameraInAR) .disabled(arToggleState) //
Topic: Graphics & Games SubTopic: RealityKit Tags:
Replies
Boosts
Views
Activity
May ’26
Glass effect interactive effect issue when used with concentric shapes
Using .glassEffect(.clear.interactive(), in: shape), where shape is some concentric shape that adapts to corner radius of the device, results in appearing of highlighted capsule shape. Code to reproduce this behavior import SwiftUI struct HelloLiquidGlass: View { var body: some View { if #available(iOS 26.0, *) { Text(Hello, World!) .frame(maxWidth: .infinity, maxHeight: .infinity) // .glassEffect(.clear.interactive(), in: .rect(corners: .concentric)) // .glassEffect(.clear.interactive(), in: ConcentricRectangle(uniformTopCorners: .fixed(80))) .padding(36) .ignoresSafeArea() .preferredColorScheme(.dark) } } } #Preview { HelloLiquidGlass() } Either of both commented-out modifiers produces the same result when user interacts with Liquid Glass pane (revealing of capsule shape that is not relative to actual shape of liquid glass effect modifier) iOS 26.5 (23F73) SDK + iOS 26.5 (23F77) Simulator
Replies
3
Boosts
0
Views
458
Activity
May ’26
Reply to How do I dismiss a presented sheet?
Hi @coastalDev On visionOS, sheets don't dismiss when you tap outside them — that's a deliberate platform behavior, and SwiftUI doesn't expose a modifier to opt into iPadOS-style tap-outside dismissal. The Human Interface Guidelines describe a sheet on visionOS (along with macOS, tvOS, and watchOS) as always modal, meaning people can't interact with the parent view until they explicitly dismiss it. This also matches how system presentations behave on visionOS — .alert, .confirmationDialog, .fileImporter, .photosPicker, and the share sheet are all dismissed via an explicit control rather than a tap outside. Following the same pattern in your custom sheet will feel native. For a data-entry Form like yours, consider pairing a Cancel button with a Done (or Save) button as text buttons in the sheet's toolbar, as many system apps do. The Best practices section of the HIG codifies this pairing — The Cancel (or Close) button dismisses a sheet without saving any changes… The Done button dismisses a sheet afte
Replies
Boosts
Views
Activity
May ’26
SwiftUI template in Instruments 26.4.1 shows empty channels on iOS 26.4.2 device — even with a minimal TimelineView repro
Hi all, I've hit a reproducible issue where the presence of the SwiftUI instrument in a template prevents any data from being recorded, including from the other instruments in the same template. Removing the SwiftUI instrument immediately restores normal recording. Environment Host: macOS 26.4.1 (25E253), Mac mini Xcode / Instruments 26.4.1 (17E202) Device: iPhone 17, iOS 26.4.2 (23E261) (physical device, USB-attached) Symptom Recording the same app, same device, same session, only varying the template contents: SwiftUI template (as-is) => All lanes empty across the entire recording Same template with the SwiftUI instrument removed => Data collected normally (Time Profiler samples, Hangs, etc.) So it seems not an issue with the SwiftUI lanes specifically being empty — including the SwiftUI instrument appears to silence the entire recording. Steps to reproduce Open Instruments → pick the SwiftUI template (or build a custom template that inclu
Replies
3
Boosts
0
Views
1.3k
Activity
May ’26
My new thing I made
FirstByte: Code-Core is a floating developer HUD for iPad that helps decode technical acronyms, coding terminology, and infrastructure concepts in real time. Designed for developers, students, operators, and AI-assisted workflows, the app features draggable transparent overlays, flip-card explanations, customizable themes, adjustable transparency, and a compact non-intrusive interface built for multitasking. Perfect for GitHub workflows, Web3 tooling, cloud infrastructure, SwiftUI development, and learning complex technical stacks without breaking focus.
Replies
0
Boosts
0
Views
801
Activity
May ’26
Workarounds for Xcode previews errors: Cannot preview in this file - Failed to Launch
I have started to have issues with SwiftUI previews of iOS apps with projects under the Documents folder. I have experimented that in Xcode 26.4 and I am still seeing it in 26.5. The error is: Cannot preview in this file. Failed to launch xyz.abc.TestApp Looking at the diagnostics, Xcode gets a permission denied error when trying to open /Users/me/Documents/path/to/TestApp/DerivedData/TestApp/Build/Intermediates.noindex/TestApp.build/Debug-iphonesimulator/TestApp.build/Objects-normal/arm64/ContentView.1.preview-thunk-launch.o Error details below. Note that I have set DerivedData folders relative to the projects' roots. Additional information: I get errors on freshly created iOS projects, just trying to preview the default ContentView. Xcode has full disk access set in System Preferences > Privacy & Security. I have cleaned build folders, deleted the simulators, Xcode itself, cleared various caches, restarted and reinstalled Xcode to no avail. Checking Editor > Canvas > Use Legacy Preview
Replies
4
Boosts
0
Views
522
Activity
May ’26
Overlay window above all windows, even when moving spaces
Hi! I would like to overlay a macOS application window above all windows, even when moving spaces or moving to a fullscreen app, similar in function to the DropOver app for macOS. What I have tried: Overwriting the default app delegate in SwiftUI and creating the NSWindow myself. Then setting the window.collectionBehavior to [.canJoinAllApplications, .canJoinAllSpaces, .fullScreenAuxiliary] and the window.level to .floating or .statusBar. This works for moving between Spaces, but still does not display above apps in fullscreen mode. I also registered a notification observer for NSWorkspace.activeSpaceDidChangeNotification, where I call window.orderFrontRegardless() to always have my window frontmost. Still not displaying above fullscreen apps. What am I missing to make this work? Best regards
Replies
2
Boosts
0
Views
694
Activity
May ’26
Reply to Xcode 26.4: IBOutlets/IBActions gutter circles missing — cannot connect storyboard to code (works in 26.3)
In the same way, @IBDesignable, @IBInspectable have disappeared some time ago. Is it only with objC code or Swift as well ? I do hope I'm wrong, but sometimes, looks like they are silently killing IB to force developers to SwiftUI. That would be very very negative evolution.
Replies
Boosts
Views
Activity
May ’26
How to optimize SwiftData performance in large lists?
I’m building a SwiftUI application using SwiftData for local storage. When loading large lists with images, scrolling performance becomes slower. What are the best practices to optimize SwiftData fetch performance in SwiftUI apps?
Replies
1
Boosts
0
Views
543
Activity
May ’26