Post

Replies

Boosts

Views

Activity

Swift Concurrency (async let) - Cancellation
I am a bit confused about tasks being cancelled. Overview: checkCancellation function has 2 child tasks: computeA and computeB that run concurrently, computeB throws an error. Doubt: I expected child task computeA to be cancelled because computeB threw an error, but computeA was never cancelled. Is my understanding wrong or am I missing something? Or is this a bug? Note: I am using a SwiftUI project (as Swift Playgrounds don't support async let) macOS Big Sur 11.5.2 (20G95) Xcode Version 13.0 beta 5 (13A5212g) Output: A - started B - going to throw A - going to return, Task.isCancelled = false error: infinity Concurrent Function Definitions: import Foundation import UIKit enum ComputationError: Error { case infinity } fileprivate func computeA() async throws -> Int { print("A - started") await Task.sleep(2 * 100_000_000) print("A - going to return, Task.isCancelled = \(Task.isCancelled)") //I expected Task.isCancelled to be true return 25 } fileprivate func computeB() async throws -> Int { print("B - going to throw") throw ComputationError.infinity } func checkCancellation() async throws { async let a = computeA() async let b = computeB() let c = try await a + b print("c = \(c)") } Invoking Concurrent function struct ContentView: View { var body: some View { Button("check cancellation") { Task { do { try await checkCancellation() print("normal exit") } catch { print("error: \(error)") } } } } }
4
0
1.4k
Dec ’21
@FocusedBinding not working for iOS (using it for Commands)
Aim To use a keyboard shortcut on a Multiplatform app (iOS and macOS) When keyboard shortcut is tapped, the price needs to be printed Problem The same code doesn't work on iPad but works on macOS Question: Why is not working? How to fix this? Environment macOS Big Sur - 11.6 (20G165) Version 13.0 (13A233) Code @main struct TestApp: App { @State private var price = 0 var body: some Scene { WindowGroup { ContentView(price: $price) .focusedValue(\.price, $price) } .commands { PriceCommands() } } } struct ContentView: View { @Binding var price: Int var body: some View { IncreasePriceButton(price: $price) } } struct IncreasePriceButton: View { @Binding var price: Int var body: some View { Button("Increase Price") { price += 1 print("price = \(price)") } } } struct PriceCommandButton: View { @FocusedBinding(\.price) var price var body: some View { Button("Print Price") { print("price = \(price)") } } } struct PriceCommands: Commands { var body: some Commands { CommandMenu("Custom") { PriceCommandButton() .keyboardShortcut(KeyboardShortcut("C", modifiers: [.command, .shift])) } } } struct FocusedPriceKey: FocusedValueKey { typealias Value = Binding<Int> } extension FocusedValues { var price: FocusedPriceKey.Value? { get { self[FocusedPriceKey.self] } set { self[FocusedPriceKey.self] = newValue } } }
1
0
924
Oct ’21
Xcode Cloud to use swift 5.7 (Xcode-14)
Overview I have an existing Xcode project that works fine with Xcode Cloud I have a separate branch on to which I have migrated and made changes for Xcode 14 On the same branch I have made some code changes that is supported by Swift 5.7 Example: var price: Int? = 100 guard let price else { return } Problem Xcode code build fails with the error Variable binding in a condition requires an initializer Question: Is it possible to build Xcode Cloud on Swift 5.7 or Xcode 14?
0
0
1.1k
Jul ’22
FB11812450: DatePicker on macOS after Esc key is pressed becomes unresponsive / unselectable
Overview On macOS when a user clicks on the date in a date picker field a pop up opens with options to select the date if the user taps on Esc key, then there is no option to select that field or any other field. Feedback: FB11812450 Questions: Am I missing something? Is this a bug? (Feedback: FB11812450) Steps to reproduce Run the code (see below) on macOS Click on the date portion of the date picker field A pop up opens Press the Esc key Actual Behaviour You can't select the date picker again to change the date. Expected Behaviour When the the escape key is pressed the popup should close and the date picker and other text fields should be selectable again. Code struct ContentView: View { @State private var date = Date() @State private var note = "hello world" var body: some View { VStack { DatePicker("Birthday", selection: $date) TextField("Note", text: $note) } } }
1
0
950
Nov ’22
iPad NavigationSplitView - Detect if contentView is a slide over
Overview I have a 3 column NavigationSplitView On iPad I would like to detect if the sidebar (red) / content (green) is a slide over I don't want to rely on orientation as it is possible to have multiple apps side by side and that can change the view size Questions: On iPad, how can I detect if sidebar (red) / content (green) is a slide over? Or is there an alternate approach? Code: struct ContentView: View { @State private var splitViewVisibility = NavigationSplitViewVisibility.automatic var body: some View { NavigationSplitView(columnVisibility: $splitViewVisibility) { Color.red } content: { Color.green } detail: { Color.blue } } } Screenshot Slide over Not Slide Over
0
0
814
Nov ’22
Beta app review submission failed (Submission limit has been reached.)
Hi, I have Xcode Cloud setup for external testers to test my app which is not yet released on the App Store. It is a multi platform app, the iOS app is successful and is available for testing. TestFlight External Testing - macOS (Post-Actions) status: iOS: Successful (available for external testers) macOS: Failed - Beta app review submission failed (Submission limit has been reached.) Developer Server Status doesn't seem to show any outages. It would be great if it could be fixed and also if it is related to Apple Server issues it would be great if this is also tracked so that it is more transparent and is alerted to the relevant team to be fixed @Jason could you help with this, many thanks!
0
0
1.3k
Dec ’22
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
EditButton causes the selection in sidebar view to be lost
Problem When app is run on iPhone 14 pro simulator running iOS 17 tapping on the EditButton shows the text "No folder selected" Feedback Feedback ID: FB12953838 Steps to reproduce: Run the app on iOS 17 iPhone simulator Tap on the "Edit" Button Expected Behaviour The view should show the car list in the edit mode Actual Behaviour The view shows the text "No folder selected" Note: Problem happens only the first time, subsequently EditButton works fine. Environment: iOS: 17 Platform: iPhone 14 pro simulator Xcode: 15.0 beta 6 (15A5219j) Code ContentView import SwiftUI struct ContentView: View { @State private var selectedFolderID: Int? @StateObject private var dataStore = DataStore() var body: some View { NavigationSplitView { FolderListView( selectedFolderID: $selectedFolderID, dataStore: dataStore ) } detail: { if let selectedFolderID { CarListView( selectedFolderID: selectedFolderID, dataStore: dataStore ) } else { Text("No folder selected") } } } } FolderListView import SwiftUI struct FolderListView: View { @Binding var selectedFolderID: Int? @ObservedObject var dataStore: DataStore var body: some View { List(dataStore.folders, selection: $selectedFolderID) { folder in NavigationLink(value: folder.id) { Text(folder.name) } } .task { selectedFolderID = dataStore.folders.first?.id } } } CarListView import SwiftUI struct CarListView: View { let selectedFolderID: Int @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { List( dataStore.cars(withFolderID: selectedFolderID), selection: $selectedCarIDs ) { car in Text(car.name) } .toolbar { //Tapping on the EditButton on the iPhone, shows the text "No folder selected". EditButton() } } } DataStore import Foundation class DataStore: ObservableObject { @Published var folders = [Folder(id: 0, name: "Folder 1"), Folder(id: 1, name: "Folder 2"), Folder(id: 2, name: "Folder 3"), Folder(id: 3, name: "Folder 4"), Folder(id: 4, name: "Folder 5")] @Published var carIDsInFolder: [Folder.ID : [Car.ID]] = [0: [0, 1], 1: [2, 3], 2: [4, 5], 3: [6, 7], 4: [8, 9]] @Published var cars = [Car(id: 0, name: "aaa", price: 100), Car(id: 1, name: "bbb", price: 110), Car(id: 2, name: "ccc", price: 120), Car(id: 3, name: "ddd", price: 130), Car(id: 4, name: "eee", price: 140), Car(id: 5, name: "fff", price: 150), Car(id: 6, name: "iii", price: 160), Car(id: 7, name: "jjj", price: 170), Car(id: 8, name: "***", price: 180), Car(id: 9, name: "lll", price: 190)] func cars(withFolderID folderID: Folder.ID) -> [Car] { let carIDs = carIDsInFolder[folderID] ?? [] return carIDs.compactMap { car(withID: $0) } } func car(withID carID: Car.ID) -> Car? { cars.first { $0.id == carID } } } Car import Foundation struct Car: Identifiable { var id: Int var name: String var price: Int } Folder import Foundation struct Folder: Identifiable { var id: Int var name: String }
2
0
771
Aug ’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
Tapping on ShareLink crashes the app
Overview Tapping on ShareLink crashes the app when ShareLink is added in the toolbar with the placement of secondaryAction Feedback FB21337385 Note: Apple engineers please priorities this is a blocker and affects production apps and prevents us from going live. Environment Xcode: 26.2 (17C52) iOS: 26.2 iPadOS: 26.2 Reproduce Able to reproduce 100% both on Simulator and Device Isolation of the crash The crash happens only when the ShareLink is used with the placement .secondaryAction The crash doesn't 'happen when the ShareLink is used with the placement .primaryAction Code import SwiftUI struct ContentView: View { var body: some View { NavigationStack { Text("Hello, world!") .toolbar { ToolbarItem(placement: .primaryAction) { Button("Dummy") { print("dummy") } } // Tapping on share button will cause it to crash // Crash only happens when the ShareLink is used with placement .secondaryAction // It doesn't crash when placement is primaryAction ToolbarItem(placement: .secondaryAction) { ShareLink(item: "Some string") } } } } } Crash stack trace *** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIActivityViewControllerPresentationController: 0x105a3b580>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.' *** First throw call stack: ( 0 CoreFoundation 0x00000001804f71d0 __exceptionPreprocess + 172 1 libobjc.A.dylib 0x000000018009c094 objc_exception_throw + 72 2 UIKitCore 0x0000000185a5b17c -[UIPopoverPresentationController presentationTransitionWillBegin] + 2712 3 UIKitCore 0x0000000185a65de0 -[UIPresentationController _presentationTransitionWillBegin] + 28 4 UIKitCore 0x0000000185a6523c __80-[UIPresentationController _initViewHierarchyForPresentationSuperview:inWindow:]_block_invoke + 1928 5 UIKitCore 0x0000000185a633ec __77-[UIPresentationController runTransitionForCurrentStateAnimated:handoffData:]_block_invoke_3 + 296 6 UIKitCore 0x00000001868b2950 -[_UIAfterCACommitBlock run] + 64 7 UIKitCore 0x00000001868b2d64 -[_UIAfterCACommitQueue flush] + 164 8 UIKitCore 0x0000000186354f04 _runAfterCACommitDeferredBlocks + 256 9 UIKitCore 0x0000000186346bec _cleanUpAfterCAFlushAndRunDeferredBlocks + 76 10 UIKitCore 0x0000000186346cb4 _UIApplicationFlushCATransaction + 68 11 UIKitCore 0x0000000186263c48 __setupUpdateSequence_block_invoke_2 + 372 12 UIKitCore 0x000000018582f378 _UIUpdateSequenceRunNext + 120 13 UIKitCore 0x00000001862640a4 schedulerStepScheduledMainSectionContinue + 56 14 UpdateCycle 0x00000002501912b4 _ZN2UC10DriverCore18continueProcessingEv + 80 15 CoreFoundation 0x000000018041a4ac __CFMachPortPerform + 164 16 CoreFoundation 0x0000000180456aa8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56 17 CoreFoundation 0x00000001804560c0 __CFRunLoopDoSource1 + 480 18 CoreFoundation 0x0000000180455188 __CFRunLoopRun + 2100 19 CoreFoundation 0x000000018044fcec _CFRunLoopRunSpecificWithOptions + 496 20 GraphicsServices 0x0000000192a669bc GSEventRunModal + 116 21 UIKitCore 0x0000000186348574 -[UIApplication _run] + 772 22 UIKitCore 0x000000018634c79c UIApplicationMain + 124 23 SwiftUI 0x00000001da58d620 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 164 24 SwiftUI 0x00000001da58d368 $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 180 25 SwiftUI 0x00000001da31b42c $s7SwiftUI3AppPAAE4mainyyFZ + 148 26 ShareLinkSecondaryPlacementDemo.deb 0x0000000104d82b0c $s31ShareLinkSecondaryPlacementDemo0abcdE3AppV5$mainyyFZ + 40 27 ShareLinkSecondaryPlacementDemo.deb 0x0000000104d82bb8 __debug_main_executable_dylib_entry_point + 12 28 dyld 0x0000000104cc53d0 start_sim + 20 29 ??? 0x0000000104ff0d54 0x0 + 4378791252 ) libc++abi: terminating due to uncaught exception of type NSException
1
0
139
Dec ’25
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
73
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
Navigation title flickers when tab is changed when used with a List / Form
Problem When a List / Form is added inside a TabView and navigationTitle is set, then switching between tabs causes the navigation title to flicker. Feedback: FB21436493 Environment Xcode: 26.2 (17C52) iOS: 26.2 (23C55) Reproducible on: Both simulator and device Root cause When List / Form is commented out, issue doesn't occur Steps to Reproduce Run app on iOS Switch between tabs Notice that the navigation title flickers Code ContentView import SwiftUI struct ContentView: View { @State private var selectedTab = TabItem.red var body: some View { NavigationStack { TabView(selection: $selectedTab) { ForEach(TabItem.allCases, id: \.self) { tab in Tab(tab.rawValue, systemImage: tab.systemImageName , value: tab) { // Problem occurs with a List / Form // Commenting out list works without flickering title List { Text(tab.rawValue) } } } } .navigationTitle(selectedTab.rawValue) } } } TabItem enum TabItem: String, CaseIterable { case red case green case blue var systemImageName: String { switch self { case .red: "car" case .green: "leaf" case .blue: "bus" } } } Screen recording:
Topic: UI Frameworks SubTopic: SwiftUI
3
0
271
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
71
Dec ’25