Post

Replies

Boosts

Views

Activity

HIDDeviceClient Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1f9e0e13c)
Hi all, I'm trying to write a little utility app that can detect when my bluetooth mouse is connected and turn natural scrolling off. I started by creating a Swift Package with swift package init --type excecutable and then wrote the following code in main.swift: import CoreHID let manager = HIDDeviceManager() let notifications = await manager.monitorNotifications( matchingCriteria: [.init(primaryUsage: .genericDesktop(.mouse))] ) for try await notification in notifications { switch notification { case .deviceMatched(let device): print("Matched:", device.deviceID) let client = HIDDeviceClient(deviceReference: device) print(await client?.manufacturer ?? "Unknown") case .deviceRemoved(let device): print("Removed:", device.description) let client = HIDDeviceClient(deviceReference: device) print(await client?.manufacturer ?? "Unknown") @unknown default: print("Unknown: \(notification)") } } This program successfully detects my bluetooth mouse and correctly prints "Logitech", but when it gets to a second device, it crashes with the error message I put in the title: EXC_BREAKPOINT (code=1, subcode=0x1f9e0e13c). If I run the program without my bluetooth mouse connected, it just crashes immediately so I can only assume this second device is the trackpad. I added some log statements in addition to the prints so I could check unified logging in Console but nothing really stood out. No code signing errors, no permission denials, nada. My environment: MacBook Air 13-inch, M3, 2024 MacOS 15.1 (24B83) Xcode Version 16.0 (16A242d) swift-tools-version: 6.0 $ swift --version swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0 Has anyone seen this before or have ideas on how to investigate further?
5
0
307
Jan ’25
Updates to data from App Intent don't trigger view refresh in app
Hi all, I'm working on a really basic counter app as a way to explore SwiftData and have come across some behavior that I don't understand. I have a very simple App Intent that increments a user-specified counter in my app. The intent doesn't throw any errors and correctly updates the CoreData store but, when I switch back to my app from the Shortcuts app (where I'm testing the app intent), the view hasn't updated. Closing and re-opening the app shows the incremented counter value but I'd like to know if it's possible to have my app's UI update when the CoreData store is updated from outside the app without relaunching the whole app. For some brief context, here's my view and the App Intent: struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query private var counters: [Counter] // ... var body: some View { NavigationStack { List { ForEach(counters) { counter in CounterRowItem(counter: counter) } .onDelete(perform: deleteItems) } // ... } } struct IncrementCounterIntent: AppIntent { static var title: LocalizedStringResource = "Increment Counter" @Parameter(title: "Name", optionsProvider: CounterOptionsProvider()) var name: String func perform() async throws -> some IntentResult & ReturnsValue<Int> { let provider = try CounterProvider() guard let counter = try provider.fetchCounters().first(where: { $0.name == name }) else { print("Couldn't find counter with name '\(name)'") return .result(value: 0) } counter.count += 1 try provider.context.save() return .result(value: counter.count) } private final class CounterOptionsProvider: DynamicOptionsProvider { func results() async throws -> [String] { try CounterProvider().fetchCounters().map { $0.name } } } }
8
5
2.5k
Sep ’23