Search results for

swiftui

16,642 results found

Post

Replies

Boosts

Views

Activity

Reply to AppKit - Legal to Change a View's Frame in -viewDidLayout?
Thanks for the post, it’s hard not seeing the code and how you're setting constrains in code. Would you be so kind to provide your code where you setting the constraints so developers here can see it? What do you mean by legal? it is generally not a good idea (and will lead to crashes) to directly modify the frame or bounds of a view that is managed by Auto Layout in my opinion. In my experience any method that directly or indirectly causes setNeedsLayout() or setNeedsDisplay() or changes the frame or bounds of a view that is managed by Auto Layout, may likely trigger the same infinite loop and exception. I think AppKit's layout cycle (especially with Auto Layout) translatesAutoresizingMaskIntoConstraints creates weird fixed width and height constraints leading to Unable to simultaneously satisfy constraints warnings isn’t? When you then add a view add an explicit Auto Layout constraints to a view hierarchy where translatesAutoresizingMaskIntoConstraints is true for some views, you often end up with conflicti
Topic: UI Frameworks SubTopic: AppKit Tags:
9h
SwiftUI TextEditor: replaced text jumps outside current selection
I have a text editor where I replace the selected text when a button is tapped. Most of the time it works, but sometimes the new text is inserted at the end of the text instead of at the selected position. Is this a bug? @Bindable var note: Richnote @State private var selection = AttributedTextSelection() var body: some View { VStack { TextEditor(text: $note.content, selection: $selection) Button(Replace text) { let textToInsert = A long text that makes me think lalala note.content.replaceSelection(&selection, withCharacters: textToInsert) }
Topic: UI Frameworks SubTopic: SwiftUI
1
0
26
9h
Why MapKit Is So Unpredictable for macOS?
I have an existing iOS app with MapKit. It always shows the current user location with UserAnnotation. But the same isn't true for macOS. I have this sample macOS application in SwiftUI. In the following, the current user location with a large blue dot appears only occasionally. It won't, 19 of 20 times. Why is that? I do have a location privacy key in Info.plist. And the Location checkbox is on under Signing & Capabilities. import SwiftUI import MapKit struct ContentView: View { @State private var markerItems: [MarkerItem] = [ MarkerItem(name: Farmers Market 1, lat: 35.681, lon: 139.691), MarkerItem(name: Farmers Market 2, lat: 35.685, lon: 139.695), MarkerItem(name: Farmers Market 3, lat: 35.689, lon: 139.699) ] @State private var position: MapCameraPosition = .automatic var body: some View { Map(position: $position) { UserAnnotation() ForEach(markerItems, id: .self) { item in Marker(item.name, coordinate: CLLocationCoordinate2D(latitude: item.lat, longitude: item.lon)) } } .mapControl
0
0
11
10h
Tabview page dots like in the weather app
Hi, I am looking to display (in SwiftUI) the Tabview page dots like in the weather app in the toolbar, an important thing is I want to keep page controls by tapping and scrubbing. Actually, I want to do what's on Apple Design's Page Controls page; here's the link and a photo of what I'd like to do. Could you help me? https://developer.apple.com/design/human-interface-guidelines/page-controls
1
0
24
12h
tabViewBottomAccessory causes unstable view identity for views accessing Environment or State
Views placed inside tabViewBottomAccessory that access @Environment values or contain @State properties experience unstable identity, as shown by Self._printChanges(). The identity changes on every structural update to the TabView, even though the view's actual identity should remain stable. This causes unnecessary view recreation and breaks SwiftUI's expected identity and lifecycle behavior. Environment Xcode Version 26.2 (17C52) iOS 26.2 simulator and device struct ContentView: View { @State var showMoreTabs = true struct DemoTab: View { var body: some View { Text(String(describing: type(of: self))) } } var body: some View { TabView { Tab(Home, systemImage: house) { DemoTab() } Tab(Alerts, systemImage: bell) { DemoTab() } if showMoreTabs { TabSection(Categories) { Tab(Climate, systemImage: fan) { DemoTab() } Tab(Lights, systemImage: lightbulb) { DemoTab() } } } Tab(Settings, systemImage: gear) { List { Toggle(Show more Tabs, isOn: $showMoreTabs) } } } .tabViewBottomAccessory { AccessoryView() } .ta
0
0
15
15h
`ImageRenderer.render` halts program with `EXC_BREAKPOINT` inside SwiftUI/AttributeGraph
This extension View { public func renderSomething() async throws { let renderer = ImageRenderer(content: self) // renderer.colorMode = .linear renderer.render { size, context in print(size) // ... } // ... } } let view: some View = ... view.renderSomething() // → exception will cause the program to exit with EXC_BREAKPOINT deep inside SwiftUI. This worked with previous versions of Xcode, SwiftUI, and macOS. Xcode Version 26.2 (17C52), macOS Sequoia 15.7.3, using toolchain bundled with Xcode.
0
0
13
1d
Cannot overwrite Swift package default traits in Xcode
I am using swift-subprocess, and need to disable the SubprocessSpan trait because Xcode 26.2 does not ship with a bundled version libswiftCompatibilitySpan.dylib, causing everything to crash built with Xcode that happens to use Span. However, I cannot disable that trait by doing any of the following things: .package( url: https://github.com/swiftlang/swift-subprocess.git, branch: main, traits: [] ), .package( url: https://github.com/swiftlang/swift-subprocess.git, branch: main, traits: [.trait(name: SubprocessFoundation)] ), Note that SubprocessSpan is default trait in subprocess: // Enable SubprocessFoundation by default var defaultTraits: Set = [SubprocessFoundation] #if compiler(>=6.2) // Enable SubprocessSpan when Span is available [except it is not] defaultTraits.insert(SubprocessSpan) #endif The package still builds with the SubprocessSpan enabled. This is not an issue with the subprocess package. According to this, I should use swift build on the command line, yet this isn't -- as is upgrading to Ta
0
0
12
1d
SwiftUI Instruments Template doesn't work
I am profiling a simple SwiftUI test app on my new iPhone through my new MacBook Pro and everything is version 26.2 (iOS, macOS, Xcode). I run Instruments with the SwiftUI template using all of the default settings and get absolutely zero data after interacting with the app for about 20 seconds. Using the Time Profiler template yields trace data. Trying the SwiftUI template again with the sample Landmarks app has the same issue as my app.
1
0
39
1d
Reply to AVCaptureSession preview briefly goes blank after interruption (lock/unlock or camera switch) while isRunning == true
Update / Resolution In my case, the flashing preview was not a capture pipeline issue, but a SwiftUI view lifecycle issue. The camera preview was conditionally shown using: authorized && session.isRunning && cameraReady During lock/unlock or camera switches, SwiftUI re-evaluates this condition multiple times. AVCaptureSession.isRunning can briefly fluctuate during interruption recovery, causing SwiftUI to: remove the preview view show a placeholder immediately reinsert the preview This rapid view swapping appeared as a “blank flash”. The preview layer itself was fine. Fix I removed session.isRunning from the SwiftUI visibility condition. The logic is now: authorized && cameraReady cameraReady is set once after initial setup and never toggles during interruptions. The preview view stays mounted at all times. Why this works AVCaptureVideoPreviewLayer already handles short “no frames” periods gracefully. By keeping the preview layer mounted and avoiding
2d
Reply to Crash in swift::_getWitnessTable when passing UITraitBridgedEnvironmentKey
FB20843042 is the feedback we filed which includes a sample project. What is the intent of foo(key: MyCustomTraitKey.self)? It was added in an effort to identify the source of the crash by minimizing types and functions used from system SDKs. The issue occurs with any function with the same signature. The original ossie wsa found when calling https://developer.apple.com/documentation/swiftui/environmentvalues/subscript(_:)-9zku
Topic: UI Frameworks SubTopic: UIKit Tags:
2d
Reply to app bar menu items flickering swiftUI app development my ios26.2
Thank you for your post. I am attempting to understand what you are tying to accomplish. Because you are using the UIHostingController I guess you are using UIKit and SwiftUI together? It would be greatly appreciated if you could provide a focused sample to demo the issue, without code is really hard for me. In my opinion I believe this error message suggests that you are attempting to directly add a subview to the view hierarchy of a view controller, which is not suggested and can result in issues with the view hierarchy. A view controller is designed to manage its own view hierarchy, and directly tampering with it can lead to unexpected behavior. If you wish to overlay or add views around the SwiftUI content managed by a view controller, you should do so by adding your views to a common superview that contains the view controller’s view. If your objective is to integrate UIKit views into SwiftUI, consider using to encapsulate a UIKit view and incorporate it within your SwiftUI
Topic: UI Frameworks SubTopic: SwiftUI
2d
Reply to SwiftUI Instrumentation Fails to start
Updating to XCode 26.2 and macOS Tahoe 26.2 and im now greeted with Trace file had no swiftui data this occurs if I profile with XCode and chose a template I profile with XCode and chose a blank template and manually choose SwiftUI I manually run the Instruments, manually run the app, attach and open a document in my swiftUI app however, if i DO NOT load a document (macOS based swiftui app), im able to get swiftui traces my feeling here is theres something going on with complicated traces that cause an issue modelling the data stream, or capturing the trace? Im not familiar with the nuances here but this isnt working for anything that NEEDS profiling.
2d
WebAuthenticationSession doesn't seem to do anything on macOS
I'm attempting to use WebAuthenticationSession from Authentication Services (https://developer.apple.com/documentation/authenticationservices/webauthenticationsession) in a SwiftUI app on macOS. According to the docs, it is supported since macOS 13.3 and I'm testing on 26. I'm deploying the same code to iOS as well, and it works there in a simulator, but I sometimes have to tap the button that triggers the authenticate(…) call more than once. I've attached a simplified and redacted version of the code below. It works on iOS, but on macOS the authenticate call never returns. There seems to be very little documentation and discussion about this API and I'm running out of ideas for getting this to work. Is this just a bug that Apple hasn't noticed? import SwiftUI import AuthenticationServices import Combine struct PreAuthView: View { @Binding var appState: AppState @Binding var credentials: Credentials? @Environment(.webAuthenticationSession) private var webAuthenticationSession @State private
Topic: UI Frameworks SubTopic: SwiftUI
3
0
55
2d