Search results for

swiftui

16,584 results found

Post

Replies

Boosts

Views

Activity

Reply to Getting a basic URL Filter to work
AFAICT FB19582905 is with the right folks and on track to a resolution. I don’t have any info to share beyond that. FB14888965 is a SwiftUI thing, and thus far outside of my area of expertise. If you’d like to explore your options in that space, I recommend that you start a new thread over in UI Frameworks > SwiftUI. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Nov ’25
SwifUI Performance With Rapid UI Updates
The code below is a test to trigger UI updates every 30 seconds. I'm trying to keep most work off main and only push to main once I have the string (which is cached). Why is updating SwiftUI 30 times per second so expensive? This code causes 10% CPU on my M4 Mac, but comment out the following line: Text(model.timeString) and it's 0% CPU. The reason why I think I have too much work on main is because of this from instruments. But I'm no instruments expert. import SwiftUI import UniformTypeIdentifiers @main struct RapidUIUpdateTestApp: App { var body: some Scene { DocumentGroup(newDocument: RapidUIUpdateTestDocument()) { file in ContentView(document: file.$document) } } } struct ContentView: View { @Binding var document: RapidUIUpdateTestDocument @State private var model = PlayerModel() var body: some View { VStack(spacing: 16) { Text(model.timeString) // only this changes .font(.system(size: 44, weight: .semibold, design: .monospaced)) .transaction { $0.animation = nil } // no implicit animat
1
0
162
Nov ’25
Reply to SwifUI Performance With Rapid UI Updates
In your case, you're probably re-evaluating the whole ContentView body 30 times per second, which includes laying out your stacks. I'd recommend using the SwiftUI instrument in Instruments 26 to see how many times your views are being updated. There's a WWDC talk from this year about the SwiftUI instrument that I'd highly recommend, and also, if you check the Apple Developer channel on YouTube, there's a video from a recent event called Optimize your app's speed and efficiency that has a deeper dive into how to use it about an hour into the video. You might be able to get better performance from your code by isolating the updates to a child view that contains just the Text, but you also may want to look at TimelineView (docs), which specifically designed for cases like this.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’25
Clarification on SwiftUI Environment Write Performance
I'm looking for clarification on a SwiftUI performance point mentioned in the recent Optimize your app's speed and efficiency | Meet with Apple video. (YouTube link not allowed, but the video is available on the Apple Developer channel.) At the 1:48:50 mark, the presenter says: Writing a value to the Environment doesn't only affect the views that read the key you're updating. It updates any view that reads from any Environment key. [abbreviated quote] That statement seems like a big deal if your app relies heavily on Environment values. Context I'm building a macOS application with a traditional three-panel layout. At any given time, there are many views on screen, plus others that exist in the hierarchy but are currently hidden (for example, views inside tab views or collapsed splitters). Nearly every major view reads something from the environment—often an @Observable object that acts as a service or provider. However, there are a few relatively small values that are written to the environment freq
4
0
1.2k
Nov ’25
XCode problem
Right now, I am trying the tutorial for SwiftUI from the Apple Developer Program inside of Xcode, but I encountered a problem. Inside of the selectable canvas mode in Xcode, I wanted to command-control-click the element (in this case, a text) to bring up the editing popover and select Show SwiftUI Inspector. For some reason, on the popover menu, the only option was Embed. I only wanted the menu point Show SwiftUI Inspector, and I also tried the shortcut Ctrl+Option, but nothing worked. Now is there another method to get to this menu? Or can you help me with that? Noah
1
0
106
Nov ’25
MapKit detailAccessoryView buttons not working on macOS Tahoe
Hi, I have been working with an implementation of MapKit which show custom annotations with a detailCalloutAccessoryView built using SwiftUI. This has been working fine for many years, but starting with macOS Tahoe, somehow the SwiftUI buttons in this view have stopped being tappable. I have reproduced the issue in the code below ... same code works fine in macOS14 and macOS15 now doesn't work correctly in macOS26: import Cocoa import MapKit import SwiftUI class ViewController: NSViewController { private var mapView: MKMapView! override func viewDidLoad() { super.viewDidLoad() setupMapView() } private func setupMapView() { // Create and configure the map view mapView = MKMapView() mapView.translatesAutoresizingMaskIntoConstraints = false mapView.delegate = self view.addSubview(mapView) // Pin the map to all edges of the view NSLayoutConstraint.activate([ mapView.topAnchor.constraint(equalTo: view.topAnchor), mapView.leadingAnchor.constraint(equalTo: view.leadingAnchor), mapView.trai
2
0
150
Nov ’25
Reply to MapKit detailAccessoryView buttons not working on macOS Tahoe
Thanks for filing FB20975128. While we investigate, I suggest switching your buttons to AppKit types as a workaround. It sounds like you're using SwiftUI to share the callout code between macOS and iOS, so I realize the impact of using platform-specific code here, but that will at least give you a path forward while this is investigated. — Ed Ford,  DTS Engineer
Nov ’25
Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() let fetchedData = try? modelContext.fetch(fetchRequest) print(Fetched count: (fetchedData?.count ?? 0)) if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image(DefaultProfile) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Nov ’25
EditButton selection gets cleared when confirmationDialog appears in SwiftUI List
I'm experiencing an issue where my List selection (using EditButton) gets cleared when a confirmationDialog is presented, making it impossible to delete the selected items. Environment: Xcode 16.0.1 Swift 5 iOS 18 (targeting iOS 17+) Issue Description: When I select items in a List using EditButton and tap a delete button that shows a confirmationDialog, the selection is cleared as soon as the dialog appears. This prevents me from accessing the selected items to delete them. Code: State variables: @State var itemsSelection = Set() @State private var showDeleteConfirmation = false List with selection: List(currentItems, id: .self, selection: $itemsSelection) { item in NavigationLink(value: item) { ItemListView(item: item) } } .navigationDestination(for: Item.self) { item in ItemViewDetail(item: item) } .toolbar { ToolbarItem(placement: .primaryAction) { EditButton() } } Delete button with confirmation: Button { if itemsSelection.count > 1 { showDeleteConfirmation = true } else { deleteItemsSelected() } } la
1
0
140
Nov ’25
Reply to Xcode 26.1 RC issue
Using SwiftUI, the crashes of MercuryPosterExtension (half a second of distance from one another) are showing directly and make it impossible to use Xcode. Filed a feedback (FB20978029). Just to note: the Feedback app crashed during the process...
Nov ’25
Reply to VZVirtualMachineView in SwiftUI App
I derived a solution from https://github.com/insidegui/VirtualBuddy/blob/main/VirtualUI/Source/Session/Components/SwiftUIVMView.swift The solution is to create an NSViewController that controls the VZVIrtualMachineView and then wrap it with a Representable. It would be great to have the Apple Virtualization sample apps use SwiftUI 5.0, as now it is not just an alternative, but what shall be used to develop Apps. Providing XIB samples will just make the transition to best architecture (@Observable, flagged onAppear rather than viewDidLoad...)
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’25
As soon as I run the app in debug the breakpoints are disabled
After updating my system to macOS Tahoe 26.1 and Xcode 26.1, all breakpoints in my project fail to work. When I run the application in Debug mode, any enabled breakpoint (blue) immediately becomes disabled (grayed out) the moment the app launches. The application runs, but the debugger never stops. This issue occurs in any location, including in the application's init() method, which should always be hit. This behavior suggests that the LLDB debugger is failing to attach to the process at launch or is being instructed not to enable breakpoints. System Configuration: Mac Model: MacBook Pro 14 (2021), Apple M1 Pro macOS Version: Tahoe 26.1 Xcode Version: 26.1 Project Type: SwiftUI App for macOS Troubleshooting Steps Performed (All Unsuccessful): We have performed an extensive series of troubleshooting steps to resolve the issue, none of which have worked. These steps include: Basic Project Cleaning: Cleaned the build folder (Product > Clean Build Folder). Deleted the entire DerivedData directory. De
1
0
227
Nov ’25
Drag & Drop with view hierarchy
Hi! I wrote a SwiftUI based app which does use a layout similar to a calendar. A week view with 5 day-views. Each day view may contain several record views. I've implemented a drag for the records which works well inside a day view (up and down) but I can't get it working between the days. Here is an example how it looks: Any idea or example how to get the proper coordinate information related to the week view inside the rectangle view? A GeometryReader inside the Rectangle view does not give me the needed information. I have currently no idea how to implement it properly…
Topic: UI Frameworks SubTopic: SwiftUI
1
0
77
Nov ’25
Reply to Clarification on SwiftUI Environment Write Performance
@StevenPeterson Thanks for chiming in and thanks for the video itself, much appreciated. No, the view bodies are only run if the body uses the environment value for the key(s) used in that view and the value changes. That makes a lot more sense to me and aligns with the simple demo app I made to test out my original question. Consider: struct ContentView: View { @Environment(.name) var name @Environment(.age) var age var body: some View { Text(name) } } If .name is updated anywhere, then ContentView.body will be run but if .age is updated anywhere, then body is not run because .age is not referenced in the body. What worried me was that if somewhere else a view wrote to .address, then ContentView would be re-evaluated even though it doesn't refer to .address in any way. That's how I (incorrectly) interpreted the slide above. But in SwiftUI, an update doesn't always cause the view body to run again, but there is still a cost associated with these updates. That's the real clarifying statement, for me.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’25
Reply to Clarification on SwiftUI Environment Write Performance
Hi! I'll try to provide some clarification: Does writing any value to the environment really cause all views in the entire SwiftUI view hierarchy that read any environment key to have their body re-evaluated? No, the view bodies are only run if the body uses the environment value for the key(s) used in that view and the value changes. But in SwiftUI, an update doesn't always cause the view body to run again, but there is still a cost associated with these updates. In Instruments, these updates are labeled as skipped. The demo in the video shows that the cumulative cost of all the skipped updates (seen in the Consequences detail view) is significant, even without their associated view bodies running (the view that demonstrates this in the video is called CardBackView). Do environment writes only affect child views, or do they propagate through the entire SwiftUI hierarchy? Great question! This only applies to child views of the .environment modifier that you're writing with. So if Vi
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’25