Using tap on a SwiftUI Toggle wasn’t working for me:

    let app = XCUIApplication()
    let sw = app.switches["My SwiftUI Toggle"]
    XCTAssert(sw.value as! String == "0")
    sw.tap()
    XCTAssert(sw.value as! String == "1")

The above fails. I think this is because tapping the label part of the Toggle does nothing. Instead, I try to tap the switch part of it, which works:

    let app = XCUIApplication()
    let sw = app.switches["My SwiftUI Toggle"]
    XCTAssert(sw.value as! String == "0")
    sw.coordinate(withNormalizedOffset: CGVector.zero).withOffset(CGVector(dx: sw.frame.width - 10, dy: sw.frame.height / 2)).tap()
    XCTAssert(sw.value as! String == "1")

Now it works - I tap in the vertical center, on the right side of the switch, minus ten points.