Post

Replies

Boosts

Views

Activity

Swift compiler crash with Xcode 16 beta 5
This simple project just makes the Swift compiler crash in init(comparator: KeyPathComparator<RemoteComputer>): import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() } } enum CSItemOrderType: Int, Codable, CaseIterable, CustomStringConvertible { case readableName case lastConnectionDate case numberOfConnections var description: String { switch self { case .readableName: return "STR_NAME" case .lastConnectionDate: return "STR_LAST_CONN_DATE" case .numberOfConnections: return "STR_ORDER_MOST_CONNECTED" } } } struct CSItemOrder: Codable { static let allCases = [CSItemOrder(type: .readableName), CSItemOrder(type: .lastConnectionDate, order: .reverse), CSItemOrder(type: .numberOfConnections, order: .reverse)] static let allSortOrders = [KeyPathComparator(\RemoteComputer.readableName), KeyPathComparator(\RemoteComputer.lastConnectionDate), KeyPathComparator(\RemoteComputer.numberOfConnections)] let type: CSItemOrderType var order: SortOrder var comparator: KeyPathComparator<RemoteComputer> { switch type { case .readableName: return KeyPathComparator(\RemoteComputer.readableName, order: order) case .lastConnectionDate: return KeyPathComparator(\RemoteComputer.lastConnectionDate, order: order) case .numberOfConnections: return KeyPathComparator(\RemoteComputer.numberOfConnections, order: order) } } init(type: CSItemOrderType, order: SortOrder = .forward) { self.type = type self.order = order } init(comparator: KeyPathComparator<RemoteComputer>) throws { switch comparator.keyPath { case \RemoteComputer.readableName: self.init(type: .readableName, order: comparator.order) case \RemoteComputer.lastConnectionDate: self.init(type: .lastConnectionDate, order: comparator.order) case \RemoteComputer.numberOfConnections: self.init(type: .numberOfConnections, order: comparator.order) default: print("Unsupported keyPath: \(comparator.keyPath)") throw ItemOrderError.unsupportedKeyPath } } } struct RemoteComputer: Codable, Hashable, Identifiable { let id: Int let name: String let hostname: String? let localIpAddress: String? let vncPort: Int let sshPort: Int let publicIpAddress: String? let publicPort: Int let macAddress: String let scVersion: String let manualMode: Int let uuid: String let lastMappingStatus: String? let isAwake: Bool let unregistered: Bool let osVersion: String? let lastUpdate: Date let remoteAddress: String? let lastKeyboardLocale: String? let macSystemShortcuts: [String: [Int32]]? var readableName: String { return name.removingPercentEncoding ?? name } var lastConnectionDate: Date { return Date.now } var unwrappedPublicIpAddress: String { return publicIpAddress ?? NSLocalizedString("STR_NOT_AVAILABLE", comment: "") } var numberOfConnections: Int { return 0 } } enum ItemOrderError: Error { case unsupportedKeyPath } This code works fine in previous betas or Xcode 15.
4
1
945
Aug ’24
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
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
Drag via pasteboard changed on Monterey?
This code works fine on macOS 11: var body: some View {         VStack {             ActionControl()                 .padding()                 .onDrag { () -> NSItemProvider in                     let value = Action(string: "hello, world").string                     let p = ActionProfile(value: value)                     return NSItemProvider(item: p, typeIdentifier: ActionProfile.pasteboardType)                 }                          MyTextView()                 .padding()         }     } class ActionProfile: NSObject, NSCoding, NSSecureCoding { static var supportsSecureCoding: Bool = true static var pasteboardType = "com.my.app.action.profile" @objc var rawValue: String func encode(with aCoder: NSCoder) { aCoder.encode(rawValue, forKey: "value") } required init(value: String) { self.rawValue = value } required init?(coder aDecoder: NSCoder) { self.rawValue = aDecoder.decodeObject(of: NSString.self, forKey: "value")! as String } required init?(pasteboardPropertyList propertyList: Any, ofType type: NSPasteboard.PasteboardType) { return nil } } extension ActionProfile: NSPasteboardWriting, NSPasteboardReading { static var nsPasteboardType: NSPasteboard.PasteboardType = .init(pasteboardType) static func readingOptions(forType type: NSPasteboard.PasteboardType, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions { return .asKeyedArchive } func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { return [ActionProfile.nsPasteboardType] } func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? { if type == ActionProfile.nsPasteboardType { return try! NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false) } return nil } static func readableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { return [ActionProfile.nsPasteboardType] } } extension MyTextViewControl { override internal var writablePasteboardTypes: [NSPasteboard.PasteboardType] { return [ActionProfile.nsPasteboardType] + super.writablePasteboardTypes } override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool { return true } override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { let location = self.characterIndexForInsertion(at: self.convert(sender.draggingLocation, from: nil)) self.setSelectedRange(NSRange(location: location, length: 0)) return sender.draggingSource is MyTextViewControl ? .move : .copy } override func performDragOperation(_ sender: NSDraggingInfo) -> Bool { let pboard = sender.draggingPasteboard if pboard.availableType(from: [ActionProfile.nsPasteboardType]) == ActionProfile.nsPasteboardType { if let profiles = pboard.readObjects(forClasses: [ActionProfile.self], options: nil) as? [ActionProfile], !profiles.isEmpty { let alert = NSAlert() alert.messageText = "WORKS" alert.runModal() return true } else { let alert = NSAlert() alert.messageText = "FAILED" alert.runModal() return super.performDragOperation(sender) } } return super.performDragOperation(sender) } } On macOS 12 beta, when calling pboard.readObjects(...) I get this error when trying to drag the item into a NSTextView: Failed to initialize keyed unarchiver for pasteboard data: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?} I've noticed that encode(with aCoder: NSCoder) isn't called at all on macOS 12 but is on macOS 11. Are there any changes in macOS 12 regarding NSCoding or NSSecureCoding or is this just a bug?
2
0
1.1k
Jul ’21
Buttons with label won't show in keyboard shortcuts list on iPad
Why won't a button using a Label show in the keyboard shortcuts list (holding ⌘ key)? struct ContentView: View { var body: some View { NavigationSplitView { SidebarView() } detail: { Text("Hello, world") } } } struct SidebarView: View { let items = [1, 2, 3, 4, 5, 6] var body: some View { List(items, id:\.self) { item in Text("\(item)") } .toolbar { Button { // Do something } label: { Label("New", systemImage: "plus") } .keyboardShortcut("n") // Will NOT show in shortcuts list Button("Play") { // Do something } .keyboardShortcut("p") // Will show in shortcuts list } } } Am I doing something wrong or is this just yet another SwiftUI shortcoming?
2
0
657
Dec ’22
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
.refreshable on macOS?
Is .refreshable supposed to do anything on macOS? Works fine on iOS and iPadOS but it's not triggered on macOS. It's available since macOS 12 but the documentation doesn't mention anything about that. https://developer.apple.com/documentation/swiftui/view/refreshable(action:)
2
1
1.1k
Mar ’24
Swift compiler crash in Xcode 15 beta 3 (15A5195k)
Somehow the Swift compiler is unable to this code: @Observable class ServiceBrowser: NSObject { typealias ResolveServiceCompletionBlock = (Bool, Error?) -> Void fileprivate var resolveServiceCompletionHandler: ResolveServiceCompletionBlock? = nil } Here's the crash: 4 . While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/luc/Work/Repositories/app-shared/App/Shared/Connectivity/ServiceBrowser.swift") 5 . While silgen init accessor SIL function "@$s7App14ServiceBrowserC07resolveB17CompletionHandler33_5B15C352D9CC926D1F8A0ECAC5970199LLySb_s5Error_pSgtcSgvi". for init for resolveServiceCompletionHandler (at /Users/luc/Work/Repositories/ap-shared/App/Shared/Connectivity/ServiceBrowser.swift:86:21) 6 . While emitting reabstraction thunk in SIL function "@$sSbs5Error_pSgIegyg_ytIegd_TR".
2
0
1.3k
Jul ’23
SwiftUI toolbar item keyboard shortcut not showing when holding command key on iPad?
How come keyboard shortcuts associated to toolbar items do not show up when you hold down the command key? import SwiftUI struct ContentView: View { var body: some View { NavigationStack { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") Button { } label: { Text("Tap Me!") } .keyboardShortcut("o", modifiers: .command) } .padding() .toolbar { ToolbarItem { Button { } label: { Image(systemName: "bolt") } .keyboardShortcut("k", modifiers: .command) } } } } } See screenshot. The shortcut for "Tap Me!" is being shown but not the one for the toolbar item. Am I doing something wrong or this is just not supported yet in SwiftUI? If that's the case, that seems to be a significant omission.
2
0
1.4k
Jul ’23
Unable to export Strings Catalog
I've spent 3 days moving localization from my older project to my new project and converted to Strings Catalog. When I tried to export, I got the Unable to build project for localization string extraction error. Read about that and the workaround seems to be to set Localisation Export Supported to NO, which I did. I worked once and now it refuses to export and complains about missing targets, which I had to remove from the export process as recommended. WTH? Or, at some point it complained about a missing Swift Package. wwdc2023-10155
2
0
1.1k
Nov ’23
manageSubscriptionsSheet not showing
Trying to debug StoreKit on device using a sandboxed user. When I want to show manageSubscriptionsSheet, the screen flashes but nothing shows. This is visible in the console: SKEngagementRemoteViewTask: Presenting system engagement request. Request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 } Present engagement request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 }, clientBundleID: com.acme.myapp Finished presenting engagement request with view service There isn't much information in the documentation so I'm not sure if it's me not doing things correctly or a bug in iOS 17.2?
2
0
878
Nov ’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