Search results for

“swiftui”

17,106 results found

Post

Replies

Boosts

Views

Activity

Update build number automatically
In SwiftUI 6 when developing for MacOS in Xcode 26, there does not seem to be a way to provide an automatic increment of the current build number, i.e. Current Project Version in settings. Does anyone have a solution that works in the latest version of Xcode. i.e. 26? All the solutions that I have tried are based on older versions that involve running scripts to update the build file, (.xcconfig) or the .info.plist file which simply will not work in the current configuration.
0
0
383
1w
SwiftData 'simple' migration failing
This is a long post, so let me start with a summary: I am attempting to implement what ought to be a simple SwiftData migration, and am receiving the following fatal error from the ModelContainer initializer: NSCocoaErrorDomain Code=134504 Cannot use staged migration with an unknown model version. The crash occurs both in the Simulator and on a physical device. Both the original schema and the new schema load and run as expected if loaded from scratch — so I conclude the Models are OK; it is the migration from the original schema to the new schema which is the issue. I have reported this as FB22652791 and Technical Incident Case # 19893980. I have two model projects available — one contrived, the other using my actual SwiftData models. Now the Details I am developing a SwiftUI/SwiftData app. I am (currently) using Xcode 26.5-beta-3. I set up an alpha-test build using the following approach: public class DatabaseSchema { public let dbSchema: Schema = Schema([ Model1.self, ... , Model16.self ], version
6
0
459
1w
Reply to How to handle all the core AppleEvents
You're right that SwiftUI covers oapp/rapp/odoc/quit natively, plus GURL via the .onOpenURL modifier. For the events you're asking about: Open content — could you clarify which event you mean? If you're thinking of GURL (Open URL / open this URL or content), that's the onOpenURL path. If you mean something else (a custom ocon or app-specific event), let me know and I can answer specifically. Print document (pdoc) — SwiftUI does not route this to NSApplicationDelegate.application(_:printFiles:withSettings:showPrintPanels:). I verified by sending osascript -e 'tell application Test to print POSIX file ...' to test apps using both WindowGroup and DocumentGroup in macOS 26.4 — the delegate method never fired. So the standard delegate path is silent under SwiftUI. The path that does work is registering directly with NSAppleEventManager. Install your handler in applicationWillFinishLaunching: (before any events arrive) and SwiftUI doesn't fight you for ownership: @main struct MyA
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1w
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
1w
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:
1w
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:
1w
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:
1w
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:
1w
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:
1w
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
284
2w
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
2w
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
2
0
122
2w
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
734
2w
Update build number automatically
In SwiftUI 6 when developing for MacOS in Xcode 26, there does not seem to be a way to provide an automatic increment of the current build number, i.e. Current Project Version in settings. Does anyone have a solution that works in the latest version of Xcode. i.e. 26? All the solutions that I have tried are based on older versions that involve running scripts to update the build file, (.xcconfig) or the .info.plist file which simply will not work in the current configuration.
Replies
0
Boosts
0
Views
383
Activity
1w
SwiftData 'simple' migration failing
This is a long post, so let me start with a summary: I am attempting to implement what ought to be a simple SwiftData migration, and am receiving the following fatal error from the ModelContainer initializer: NSCocoaErrorDomain Code=134504 Cannot use staged migration with an unknown model version. The crash occurs both in the Simulator and on a physical device. Both the original schema and the new schema load and run as expected if loaded from scratch — so I conclude the Models are OK; it is the migration from the original schema to the new schema which is the issue. I have reported this as FB22652791 and Technical Incident Case # 19893980. I have two model projects available — one contrived, the other using my actual SwiftData models. Now the Details I am developing a SwiftUI/SwiftData app. I am (currently) using Xcode 26.5-beta-3. I set up an alpha-test build using the following approach: public class DatabaseSchema { public let dbSchema: Schema = Schema([ Model1.self, ... , Model16.self ], version
Replies
6
Boosts
0
Views
459
Activity
1w
Reply to ViewBridge to RemoteViewService Terminated (...)
先确认应用是否是前台应用 — 检查 NSApp.isActive、窗口是否在其他应用后面 再确认窗口是否是 key window — 检查 canBecomeKey、isKeyWindow 最后确认控件是否能接收事件 — SwiftUI vs AppKit 的 ViewBridge 冲突
Topic: UI Frameworks SubTopic: AppKit
Replies
Boosts
Views
Activity
1w
Reply to How to handle all the core AppleEvents
You're right that SwiftUI covers oapp/rapp/odoc/quit natively, plus GURL via the .onOpenURL modifier. For the events you're asking about: Open content — could you clarify which event you mean? If you're thinking of GURL (Open URL / open this URL or content), that's the onOpenURL path. If you mean something else (a custom ocon or app-specific event), let me know and I can answer specifically. Print document (pdoc) — SwiftUI does not route this to NSApplicationDelegate.application(_:printFiles:withSettings:showPrintPanels:). I verified by sending osascript -e 'tell application Test to print POSIX file ...' to test apps using both WindowGroup and DocumentGroup in macOS 26.4 — the delegate method never fired. So the standard delegate path is silent under SwiftUI. The path that does work is registering directly with NSAppleEventManager. Install your handler in applicationWillFinishLaunching: (before any events arrive) and SwiftUI doesn't fight you for ownership: @main struct MyA
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
1w
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
1w
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
1w
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
1w
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
1w
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
1w
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
1w
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
1w
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
284
Activity
2w
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
2w
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
2
Boosts
0
Views
122
Activity
2w
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
734
Activity
2w