Post

Replies

Boosts

Views

Activity

Generic parameter 'SelectionValue' could not be inferred
Hi! What is wrong with this code and why does this work for a Picker but not a List? struct ContentView: View {     enum FooBar: CaseIterable, Identifiable {         public var id : String { UUID().uuidString }                 case foo         case bar         case buzz         case bizz     }     @State var selectedFooBar: FooBar = .bar     var body: some View {         VStack {             Picker("Select", selection: $selectedFooBar) {                 ForEach(FooBar.allCases) { item in                     Text(self.string(from: item)).tag(item)                 }             }                         List(FooBar.allCases, selection: $selectedFooBar) { item in                 Text(self.string(from: item)).tag(item)             }                         Text("You selected: \(self.string(from: selectedFooBar))")         }     }     private func string(from item: FooBar) -> String {         var str = ""                  switch item {         case .foo:             str = "Foo"                      case .bar:             str = "Bar"                      case .buzz:             str = "Buzz"                      case .bizz:             str = "Bizz"         }         return str     } }
3
0
3.6k
Sep ’22
@Observable and didSet?
I'm in the process of migrating to the Observation framework but it seems like it is not compatible with didSet. I cannot find information about if this is just not supported or a new approach needs to be implemented? import Observation @Observable class MySettings { var windowSize: CGSize = .zero var isInFullscreen = false var scalingMode: ScalingMode = .scaled { didSet { ... } } ... } This code triggers this error: Instance member 'scalingMode' cannot be used on type 'MySettings'; did you mean to use a value of this type instead? Anyone knows what needs to be done? Thanks!
11
3
4.6k
Jan ’25
onDrag conflicts with clicks on macOS
I have a list of navigation links that I want to be draggable. However, it seems like onDrag conflicts with mouse clicks on macOS (iOS is fine). Here's some sample code: swift import SwiftUI struct ContentView: View { var items = ["Peter", "Mark", "Joe", "Frank", "Tim"] @State var selected: String? var body: some View { NavigationView { List { ForEach(items, id: \.self) { item in NavigationLink(destination: Text(item), tag: item, selection: $selected, label: { Text(item) .onDrag { () - NSItemProvider in return NSItemProvider(object: String(item) as NSString) } }) } } Text("") } } } Here's the weird part: if you click on the text, the item doesn't get selected and the link seems disabled. However, if you click on a section of the item that is empty, then it works! Again, this works just fine on iOS. Is this a SwiftUI bug/limitation or am I doing it wrong? Thanks!
1
2
1.4k
May ’21
TestFlight for Mac: review required every single time a new build is pushed?
So I've started using TestFlight for Mac but unlike its iOS counterpart, it seems like every single build uploaded and pushed to testers has to be reviewed by Apple. This is not how that works on the iOS side. Ex: MyApp 4.1 build 1 -> Review required for both iOS and Mac MyApp 4.1 build 2 -> Review required for Mac, not iOS Is this a bug or by design? If so, this is crazy!
0
0
664
Nov ’21
Can't set focus with tab key when text fields are in a form (iPadOS)
I don't know if this is a bug but when you put text fiels in a form, pressing the Tab key on a physical keyboard will just jump to the first field and stay there: import SwiftUI struct ContentView: View { enum FocusedField { case firstName, lastName } @State var name = "" @State var lastName = "" @FocusState private var focusedField: FocusedField? var body: some View { Form { TextField("Name", text: $name) .focused($focusedField, equals: .firstName) TextField("Last", text: $lastName) .focused($focusedField, equals: .lastName) } .padding() .onAppear { focusedField = .firstName } } } This is the result: Note that this works fine on macOS or when using the Tab key on the virtual keyboard. If you put the fields into a VStack instead, you'll be able to move through the fields via the Tab key.
2
1
1.7k
Mar ’23
Symbol not found when running iPad app in Vision Pro Simulator
When I try to run my iPad app in the simulator, I get this error: dyld[25133]: Symbol not found: _$s21DeveloperToolsSupport15PreviewRegistryPAAE04makeD0AA0D0VyKFZ Referenced from: <40E6A0C8-6B05-3C87-8F68-D333EF2586EA> /Users/me/Library/Developer/CoreSimulator/Devices/DAE1996F-4A59-49CA-B55D-FE2AF0E6461F/data/Containers/Bundle/Application/B49E91FE-89D5-4496-831D-31B87A6F1170/My.app/My Expected in: <31FB64EE-D651-3287-9607-1ED38855E80F> /Library/Developer/CoreSimulator/Volumes/xrOS_21N5165g/Library/Developer/CoreSimulator/Profiles/Runtimes/xrOS 1.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport Message from debugger: killed Is this a bug, my iPad app is not compatible or there's something I need to do?
4
1
1.2k
Jul ’23
Cannot redeem offer codes on Mac App Store, works fine on App Store.
It appears there's an issue with the Mac App Store's ability to process offer codes, unlike its iOS counterpart, which handles them seamlessly. Users attempting to redeem a code on their Mac are encountering a "Cannot redeem code. Try another code" error. Considering the Mac App Store's long history, having been introduced nearly 13 years ago, it's high time for it to align with the iOS App Store's functionality. While it's close to 80% there, addressing these lingering issues would greatly improve the user experience. FB13463658
2
3
1.1k
Jan ’25
SwiftUI toolbar with IDs crash since macOS 15
I understand this is a known issue, but it’s truly unacceptable that it remains unresolved. Allowing users to customize toolbars is a fundamental macOS feature, and it has been broken since the release of macOS 15. How is it possible that this issue persists even in macOS 15.3 beta (24D5040f)? FB15513599 import SwiftUI struct ContentView: View { @State private var showEditItem = false var body: some View { VStack { VStack { Text("Instructions to reproduce the crash") .font(.title) .padding() Text(""" 1. Click on "Toggle Item" 2. In the menu go to File > New Window 3. In new window, click on "Toggle Item" """) } .padding() Button { showEditItem.toggle() } label: { Text("Toggle Item") } } .padding() .toolbar(id: "main") { ToolbarItem(id: "new") { Button { } label: { Text("New…") } } if showEditItem { ToolbarItem(id: "edit") { Button { } label: { Text("Edit…") } } } } } }
5
3
565
3w
iOS: List selection is reset to nil when app is sent to background
For some reason, a List will reset its selection to nil when the app is in the background. Steps to reproduce the issue: Run attached sample project Once the app has launched, select a name in the sidebar Move the app to the background Wait a few seconds Bring back the app to the foreground Expected result: The list selection should still be valid Actual result: The list selection is set to nil Notes: I’m using a StateObject, which should be the way to ensure that data isn’t regenerated when views are rendered. Is this a bug or something else needs to be taken care of? class AppModel: ObservableObject {     @Published var selectedPerson: Person? } @main struct NilListSelectionApp: App {     @StateObject var appModel = AppModel()     var body: some Scene {         WindowGroup {             ContentView()                 .environmentObject(appModel)         }     } } struct Person: Identifiable, Hashable {     let id: UUID     let firstname: String     init(firstname: String) {         id = UUID()         self.firstname = firstname     } } struct ContentView: View {     @EnvironmentObject private var appModel: AppModel     var body: some View {         NavigationSplitView {             SidebarView()         } detail: {             PersonView(person: appModel.selectedPerson)         }     } } struct SidebarView: View {     @EnvironmentObject private var appModel: AppModel     private let persons = [Person(firstname: "Joe"), Person(firstname: "Jane")]     var body: some View {         List(persons, id:\.self, selection: $appModel.selectedPerson) { person in             Text(person.firstname).tag(person)         }         .listStyle(.sidebar)     } } struct PersonView: View {     let person: Person?     var body: some View {         if let person {             Text(person.firstname)         }         else {             Text("No Selection")         }     } }
10
2
2.8k
Jul ’23
Allow custom tap gesture in List but maintain default selection gesture
I'm trying to create a List that allows multiple selection. Each row can be edited but the issue is that since there's a tap gesture on the Text element, the list is unable to select the item. Here's some code: import SwiftUI struct Person: Identifiable { let id: UUID let name: String init(_ name: String) { self.id = UUID() self.name = name } } struct ContentView: View { @State private var persons = [Person("Peter"), Person("Jack"), Person("Sophia"), Person("Helen")] @State private var selectedPersons = Set<Person.ID>() var body: some View { VStack { List(selection: $selectedPersons) { ForEach(persons) { person in PersonView(person: person, selection: $selectedPersons) { newValue in // ... } } } } .padding() } } struct PersonView: View { var person: Person @Binding var selection: Set<Person.ID> var onCommit: (String) -> Void = { newValue in } @State private var isEditing = false @State private var newValue = "" @FocusState private var isInputActive: Bool var body: some View { if isEditing { TextField("", text: $newValue, onCommit: { onCommit(newValue) isEditing = false }) .focused($isInputActive) .labelsHidden() } else { Text(person.name) .onTapGesture { if selection.contains(person.id), selection.count == 1 { newValue = person.name isEditing = true isInputActive = true } } } } } Right now, you need to tap on the row anywhere but on the text to select it. Then, if you tap on the text it'll go in edit mode. Is there a way to let the list do its selection? I tried wrapping the tap gesture in simultaneousGesture but that didn't work. Thanks!
3
2
1.9k
Feb ’25
iOS 17b6: Simultaneous accesses to ..., but modification requires exclusive access crash using Observation and SwiftUI
Since iOS/iPadOS beta 6, I get a crash just by simply selecting an item in the sidebar of a navigation view. The selected item is part of an app mode, with conforms to the Observation protocol: import SwiftUI import Observation @main struct MREAApp: App { @State private var appModel = AppModel.shared var body: some Scene { WindowGroup { ContentView() .environment(appModel) } } } @Observable class AppModel { static var shared = AppModel() var selectedFolder: Folder? = nil } struct Folder: Hashable, Identifiable { let id = UUID() let name: String } struct ContentView: View { @Environment(AppModel.self) private var appModel var folders = [Folder(name: "Recents"), Folder(name: "Deleted"), Folder(name: "Custom")] var body: some View { NavigationSplitView { SidebarView(appModel: appModel, folders: folders) } detail: { if let folder = appModel.selectedFolder { Text(folder.name) } else { Text("No selection") } } } } struct SidebarView: View { @Bindable var appModel: AppModel var folders: [Folder] var body: some View { List(selection: $appModel.selectedFolder) { ForEach(folders, id: \.self) { folder in NavigationLink(value: folder) { Text(folder.name) } } } } } To reproduce the bug, just tap on one of the item. Oddly enough, this works fine in the Simulator. macOS 14 beta 5 is not affected either. Apple folks: FB12981860
16
2
4.0k
Oct ’23