You can use POSIX API in Swift on MacOS

macos posix swift

Swift on macOS can access POSIX APIs by importing the Darwin module. This gives you access to low-level system calls, file operations, and other Unix functionality. In my case I needed to call openpty() function from Swift application and handle raw file descriptors.

import Darwin

// Example: Get current working directory
let cwd = getcwd(nil, 0)
if let path = cwd {
    print("Current directory: \(String(cString: path))")
    free(cwd)
}

// Example: Create a directory (if app is not sandboxed)
let result = mkdir("/tmp/testdir", 0o755)
if result == 0 {
    print("Directory created successfully")
} else {
    print("Failed to create directory: \(errno)")
}

Maximum DriverKit Driver Bundle Identifier Length is 64 Characters

macos dext driverkit

If you get sysex didFailWithError: extension category returned error error when trying to Install Dext from Communicating between a DriverKit extension and a client app sample application, in Xcode change Bundle Identifier for DriverKitSampleApp and NullDriver to shorter ones, length should not exceed 64 characters.

For example, replace com.example.apple-samplecode.dext-to-user-client with com.example.dext-to-user-client- to make sure whole identifier is not longer than 64 chars, as suggested on Apple Developer Forums.