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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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
}
}
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!
DNSServiceNATPortMappingCreate returns external port 0 since macOS 13 b3 build 23A5286i.
This was the case in macOS 12 as well (see FB9137313 and FB9139688).
Hopefully this won't take months after macOS is released before it is fixed like last time.
Latest radar: FB12579235
Also, see https://developer.apple.com/forums/thread/681836
Is it possible to have sections in a SwiftUI table? I cannot find any documentation or examples that show that it is.
When creating a new SwiftUI project (either Xcode 12 or 12.2) and selecting both CoreData and CloudKit options, running the app on an iOS device shows absolutely nothing.
This is not the case if creating a universal project and running it on macOS, which works and shows some UI.
It's just a blank screen on iOS.
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?
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?
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.
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:)
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".
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.
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
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?
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
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store
App Store Connect
Mac App Store