Post

Replies

Boosts

Views

Activity

Draggable doesn't work with multiple items in a list
Problem: On macOS, unable to drag multiple car items from FolderDetail List Single items from a list are draggable but multiple items are not draggable. Feedback FB10128110 I am really saddened that this is not fixed for over a year. Please look into this. Platform macOS 14 (beta 3), macOS 13 Steps to reproduce Run the code provided below Tap the sidebar button to show the sidebar Select "Folder 0" from the sidebar Drag "car a" into "Folder 1" (Go to Folder 2 to notice this happened successfully, you will be able to see "car a" in Folder 1) Select "Folder 0" from the sidebar Select "car a" and "car b" and try to drag them to "Folder 2" Expected Behaviour "car a" and "car b" must be both draggable (multiple items should be draggable). The entire cell needs to be draggable not just the Text. Actual Behaviour Though “car a” and “car b” are selected, when dragged only one of the 2 items is dragged You also can drag them only when dragging the Text unlike in iOS where you can drag the cell. Note: Same code works on iOS Code: UTType extension UTType { static var car = UTType(exportedAs: "com.example.DragAndDropListDemo.car") } Car import Foundation import CoreTransferable struct Car: Identifiable { var id: Int var name: String } //extension Car: Codable {} extension Car: Codable, Transferable { static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .car) } } Folder struct Folder: Identifiable, Hashable { var id: Int var name: String } DataStore class DataStore: ObservableObject { var folders = (0..<100).map { Folder(id: $0, name: "folder \($0)")} var cars = [0: [Car(id: 0, name:"car a"), Car(id: 1, name:"car b")], 1: [Car(id: 2, name:"car c"), Car(id: 3, name:"car d")]] } Views ContentView struct ContentView: View { @StateObject private var dataStore = DataStore() @State private var selectedFolder: Folder? var body: some View { NavigationSplitView { FolderList(selectedFolder: $selectedFolder, dataStore: dataStore) } detail: { FolderDetail(folder: selectedFolder, dataStore: dataStore) } } } FolderList struct FolderList: View { @Binding var selectedFolder: Folder? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolder) { folder in NavigationLink(value: folder) { Text(folder.name) .dropDestination(for: Car.self) { cars, location in print("cars = \(cars) location = \(location)") if let existingCars = dataStore.cars[folder.id] { dataStore.cars[folder.id] = existingCars + cars } else { dataStore.cars[folder.id] = cars } return true } } } } } FolderDetail struct FolderDetail: View { let folder: Folder? @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { if let folder { List(dataStore.cars[folder.id] ?? [], selection: $selectedCarIDs) { car in Text(car.name) .draggable(car) } } else { Text("no folder selected") } } }
0
0
1.1k
Jul ’23
focusedSceneValue doesn't work with Window
My observations: Passing a FocusState.Binding using focusedSceneValue seems to work only when the app uses a WindowGroup. When the app uses a Window (single window) passing the FocusState.Binding in focusedSceneValue doesn't seem to work. When app uses Window passing FocusState.Binding using focusedValue and receiving it in @FocusedValue seems to work. Question: Is this expected behaviour? (should focusedSceneValue only work for WindowGroup and not for Window?)
0
0
594
Aug ’24
On macOS Settings window navigation bar item is in the center
Hi, Overview I have a Mac app with a settings window. When I add a button it is added to the center. I want it on the trailing edge, I even tried adding it as confirmationAction but doesn’t work. Screenshot Feedback FB21374186 Steps to reproduce Run the project on mac Open the app's settings by pressing ⌘ , Notice that the Save button is in the center instead of the trailing edge Code App import SwiftUI @main struct SettingsToolbarButtonBugApp: App { var body: some Scene { WindowGroup { ContentView() } Settings { SettingsView() .frame(width: 300, height: 400) } } } SettingsView import SwiftUI struct SettingsView: View { var body: some View { NavigationStack { Form { Text("Settings window") } .toolbar { ToolbarItem(placement: .confirmationAction) { // Save button is the center instead of trailing edge Button("Save") {} } } .navigationTitle("Settings") } } }
Topic: UI Frameworks SubTopic: SwiftUI
0
0
70
Dec ’25
On macOS, app's Settings model is not deallocated even after closing Settings window
Problem On the macOS when Settings view is closed, the @State model is not deallocated Feedback FB21393010 Environment macOS: 26.2 (25C56) Xcode: 26.2 (17C52) Steps to reproduce Run the project Open app's 'Settings Look at the console logs When model is created SettingsModel - init gets printed When Settings window is closed SettingsModel - deinit is not printed, meaning it is not deallocated Code SettingsModel import SwiftUI @Observable class SettingsModel { init() { print("SettingsModel - init") } deinit { print("SettingsModel - deinit") } } SettingsView import SwiftUI struct SettingsView: View { @State var model = SettingsModel() var body: some View { Text("Settings") .font(.largeTitle) .padding(200) } } App import SwiftUI @main struct SettingsBugApp: App { var body: some Scene { WindowGroup { ContentView() } Settings { SettingsView() } } }
Topic: UI Frameworks SubTopic: SwiftUI
0
0
88
Dec ’25
In Mac app, when the Settings view that uses `@Environment(\.dismiss)` it causes the subview's models to be created multiple times.
Problem For a mac app, when the Settings view that uses @Environment(\.dismiss) it causes the subview's models to be created multiple times. Environment macOS: 26.2 (25C56) Feedback FB21424864 Code App @main struct DismissBugApp: App { var body: some Scene { WindowGroup { ContentView() } Settings { SettingsView() } } } ContentView struct ContentView: View { var body: some View { Text("Content") } } SettingsView struct SettingsView: View { @Environment(\.dismiss) private var dismiss var body: some View { VStack { Text("Settings") SectionAView() } } } SectionAView struct SectionAView: View { @State private var model = SectionAViewModel() var body: some View { Text("A") .padding(40) } } SectionAViewModel @Observable class SectionAViewModel { init() { print("SectionAViewModel - init") } deinit { print("SectionAViewModel - deinit") } } Steps to reproduce (refer to the attached video) 1 - Run the app on the mac 2 - Open app's Settings 3 - Notice the following logs being printed in the console: SectionAViewModel - init SectionAViewModel - init 4 - Tap on some other app, so that the app loses focus 5 - Notice the following logs being printed in the console: SectionAViewModel - init SectionAViewModel - deinit 6 - Bring the app back to focus 7 - Notice the following logs being printed in the console: SectionAViewModel - init SectionAViewModel - deinit Refer to screen recording
Topic: UI Frameworks SubTopic: SwiftUI
0
0
166
Dec ’25
AppIntents default value
Hi, I have created an AppIntent in which there is a parameter called price, I have set the default value as 0. @Parameter(title: "Price", default: 0) var price: Int Problem When the shortcut is run this parameter is skipped Aim I still want to price to be asked however it needs to be pre-filled with 0 Question What should I do that the shortcut can still ask the price but be pre-filled with 0?
0
0
70
Dec ’25