Post

Replies

Boosts

Views

Activity

SwiftUI TextSelection crash on macOS
I have a very simple SwiftUI app, works fine on iOS, crashes on macOS: struct ContentView: View { @State var testStr: String = "" @State var selection: TextSelection? = nil var body: some View { VStack { TextField("Test", text: $testStr, selection: $selection) .onChange(of: selection) {print("selection changed")} } .padding() } } • Start app, write something in the TextField and move the cursor around. iOS: "selection changed" Mac: nothing (Bug ?) • double click on some word both Mac and iOS: "selection changed" • write some more in the TextField iOS: selection changed Mac: crash Any idea what I am doing wrong? Gerriet.
2
0
110
3d
SMAppService with root Helper
My app needs a HelperTool which runs as root. I did in Xcode Version 14.3.1 (14E300c), macOS 13.4.1 (22F82): • Create new Project: macOS App: TestSM • Add new target: XPC Service: HelperSM • make new Property List: smProp.plist with: Label de.mdenkmann.HelperSM BundleProgram /Contents/XPCServices/HelperSM.xpc/Contents/MacOS/HelperSM • add Copy File Build Phase in TestSM for smProp.plist with: Destination: Wrapper Subpath: Contents/Library/LaunchDaemons smAppService = SMAppService.daemon(plistName: "smProp.plist") smAppService.register() now: smAppService.status = "enabled" When I do: let connectionToService = NSXPCConnection(serviceName: helperSMBundleIdentifier) I can communicate with HelperSM, but it does NOT run as root. Bad. When I do: let connectionToService = NSXPCConnection(machServiceName: "de.mdenkmann.HelperSM", options: [. privileged]) I get NSXPCConnectionInvalid when I communicate with the HelperSM. Even worse. How to get my root Helper? When I look at: System Settings → General → Login Items → Allow in the Background I see: TestSM.app 3 items; 3 items affect all users. What are these 3 items? Why Background? I want my HelperSM get started as root when called from TestSM, then run it as long as the system sees fit, then stop. It should not be called from other apps. It has no need to run in the background once TestSM stops.
2
0
1.2k
Jul ’23