Search results for

swiftui

16,623 results found

Post

Replies

Boosts

Views

Activity

AsyncRenderer causes crashes in ForEach when in Swift 6 language mode
Hi! We've recently done a big migration to Swift 6 language mode in our app and are now getting reports of crashes occurring due to closures in our SwiftUI code (most often the view builder in ForEach) not running on the main queue but instead running on the queue com.apple.SwiftUI.AsyncRenderer. One example of a call stack (ScheduleListView is our view that is in Swift 6 mode): Thread 16 #0 (null) in _dispatch_assert_queue_fail () #1 (null) in dispatch_assert_queue$V2.cold.1 () #2 (null) in dispatch_assert_queue () #3 (null) in swift_task_isCurrentExecutorWithFlagsImpl(swift::SerialExecutorRef, swift::swift_task_is_current_executor_flag) () #4 (null) in closure #2 in closure #1 in closure #1 in ScheduleListView.body.getter () #5 (null) in closure #1 in ForEachState.item(at:offset:) () #6 (null) in partial apply for closure #1 in ForEachState.item(at:offset:) () #8 (null) in partial apply for closure #1 in _withObservation(do:) () .... (We have many other crashes with similar crash reports but in oth
Topic: UI Frameworks SubTopic: SwiftUI
3
0
327
Oct ’25
SwiftUI state is maddening
I honestly thought I was getting somewhere with this, but alas, no. Every time I do anything in my List of ItemRows it jumps back to the top. Here's the setup: DataService.swift: final class DataService { static let shared = DataService() private init() {} let coreData: CoreData = CoreData() let modelData: ModelData = ModelData() } ModelData.swift: @Observable class ModelData: ObservableObject { var allItems: [ItemDetails] var standardItems: [ItemDetails] var archivedItems: [ItemDetails] init() { allItems = [] standardItems = [] archivedItems = [] } func getInitialData() { // Get all items, then split them into archived and non-archived sets, because you can't use `.filter` in a view... allItems = dataService.coreData.getAllItems() standardItems.append(contentsOf: allItems.filter { !$0.archived }) archivedItems.append(contentsOf: allItems.filter { $0.archived }) } } MainApp.swift: // Get access to the data; this singleton is a global as non-view-based functions, including the `Scene`, need to access the model
7
0
245
Oct ’25
Reply to SwiftUI state is maddening
Oh, would you look at that? It's nothing at all to do with my variables. It's SwiftUI and these damned Environment variables. This time it was @Environment(.dismiss) on the view that contains the List, not the rows inside the List. This is what is supposed to happen: The user taps a button in MainView. ItemsListView opens, which contains the List. The user does something in ListItemsView, such as deleting an Item. In order to close ItemsListView the user taps a button in that view, which merely calls dismiss(). dismiss() was used to avoid using a @State var in MainView and a corresponding @Binding var in ItemsListView. This should work, right? Wrong. What actually happens is this: The user taps a button in MainView. ItemsListView opens, which contains the List. The user swipes an ItemRow, then taps the delete button. The confirmation dialog appears, and is attached to the specific row. _dismiss is changed - for some reason - in ItemsListView, which causes the view to redraw, causing the List to redra
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to SwiftUI state is maddening
This isn't even fine-tuning, this is just trying to get the entire List to stop being redrawn when something minor happens, end even when nothing has changed! Accessibility DWC hasn't changed, but SwiftUI thinks it has, and so the List redraws every row. I swipe one row and tap the edit button, the List jumps back to the top. No reason at all for that. Nothing has changed, but SwiftUI decides @self, @identity changed so it redraws every row. How did anything change? I didn't change the .id() of the rows - they use the id of the Item which has not changed. When this @State private var showDeleteConfirmation: Bool = false changes on one row because the user swiped and tapped the delete button, the entire List is redrawn. Why? I fear I'm going to end up with hundreds of stupid little hacks to get things to work, and they'll just fail on the next point release of the OS. And, as I've said on multiple occasions over the past week, across three other posts on this subject, this did not happen unti
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Drag and Drop Question
I have several classes that cannot conform to Codable for various reasons. This, unfortunately, prevents me from using Transferable. If I serialize a class instance into a Data blob and use that for drag-and-drop, it works perfectly — the drag operation succeeds. However, the destination has no way to distinguish between different types of Data blobs. What you might need here is wrapper type that wraps the data types the app wants to receive. I recommend reviewing the documentation on Creating a transferable item for drag-and-drop operations, enabling drop interactions, and the implementation shown in Adopting Drag and Drop Using SwiftUI sample project. The sample code demonstrates how to create a custom content type, how to represent it in various transfer representations and handle both custom and multiple data types that your app expects.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to SwiftUI state is maddening
I sympathise with you. 🥲 SwiftUI may be great in some aspects, but I often find that fine tuning to achieve a precise UI behaviour is a nightmare. When it is impossible to understand why SwiftUI reacts in a certain way, you end up spending enormous time just to turn around SwiftUI to mimic UIKit behaviour. Big sigh.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
SwiftUI List with Geometry header behavior changed after building app with Xcode 26
We have a custom implementation of what we call a “Scrollable Header” in our app. After building with Xcode 26, we’ve observed a change in behavior with the List component. The issue can be seen in the attached GIF: As the user scrolls up, the header is expected to collapse smoothly, and it does—until the moment the next list item becomes visible. At that point, the header collapses prematurely, without any apparent reason. We’ve identified that this behavior occurs after the list’s data-fetching logic runs, which loads additional items as the user scrolls. Below is the ViewModifier responsible for handling the collapsing header logic: @available(iOS 18.0, *) public struct L3CollapseHeaderIOS18: ViewModifier { private let minHeight: Double = 0 private let expandedHeight: CGFloat private let L3Height = 44.0 private let isViewVisible: Bool @Binding private var currentHeight: CGFloat @State private var lastOffset: ScrollOffsetInfo = ScrollOffsetInfo(offset: 0.0, offsetToBottom: 0.0, scrollableContent: 0.0) init(
3
0
153
Oct ’25
Reply to UtilityWindow can't read @FocusedValue of main scene
Using FocusedValues in UtilityWindow as described in the documentation isn't working for me either in macOS 26.0.1. Outside of the SwiftUI documentation, I can't find any information anywhere about actually using FocusedValues in a UtilityWindow, not even example code. Your comment is the only content I've been able to find, and you're having the same issue I am. If anyone coming in from a search engine has any insight into getting this to work, please share it!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Button Glass Style Incorrect in Sheet + ScrollView on Mac Catalyst 26
Hi everyone! I've encountered an issue when using Sheet + ScrollView on Mac Catalyst: the buttons in the toolbar appear with an abnormal gray color. import SwiftUI struct ContentView: View { var body: some View { VStack { } .sheet(isPresented: .constant(true)) { Sheet() } } } struct Sheet: View { var body: some View { NavigationStack { ScrollView { // <-- no issue if use List } .toolbar { Button(action: {}) { // <-- 👀 weird gray color Image(systemName: checkmark) } } } } } Steps to Reproduce: On macOS 26.0 beta 9, use Xcode 26.0 beta 7 to create an iOS project and enable Mac Catalyst. Paste the code above. Select the Mac Catalyst scheme and run the project. The buttons in the toolbar show a strange gray appearance. If you change the ScrollView to a List in the code, the issue does not occur. FB20120285
2
0
381
Oct ’25
Reply to Unable to compile Core Image filter on Xcode 26 due to missing Metal toolchain
@Product Manager I installed the Metal Toolchain by Settings > Component panel but it's not work, the component appear in Xcode component panel, but compile error because miss Metal Toolchain I encountered the same problem even I used the Xcode26 Xcode26.0.1 Xcode26.1(https://developer.apple.com/forums/thread/805547) after two days try I fixed this problem by followed the methods in this article(https://medium.com/@sergey-pekar/how-to-fix-annoying-xcode-26-not-building-swiftui-previews-error-cannot-execute-tool-metal-due-49564e20357c) I think there is still has a bug for install Metal Toolchain at least for those migrated from Xcode26 Beta
Oct ’25
Reply to Unable to compile Core Image filter on Xcode 26 due to missing Metal toolchain
I encountered the same problem even I used the Xcode26 Xcode26.0.1 Xcode26.1(https://developer.apple.com/forums/thread/805547) after two days try I fixed this problem by followed the methods in this article(https://medium.com/@sergey-pekar/how-to-fix-annoying-xcode-26-not-building-swiftui-previews-error-cannot-execute-tool-metal-due-49564e20357c) I think there is still has a bug for install Metal Toolchain at least for those migrated from Xcode26 Beta
Topic: Graphics & Games SubTopic: Metal Tags:
Oct ’25
Reply to Xcode_26 not compiling Metal project
after two days try I fixed this problem by followed the methods in this article(https://medium.com/@sergey-pekar/how-to-fix-annoying-xcode-26-not-building-swiftui-previews-error-cannot-execute-tool-metal-due-49564e20357c), I think it is also has a bug for install Metal Toolchain at least for those migrated from Xcode26 Beta
Oct ’25