Copy/Paste not working in XCode 13 Simulators with M1 Macbook Pro

Viewed 1687

Copy/Paste not working on Xcode 13 with M1 Macbook Pro simulators. It was working on a normal Mac PC.

4 Answers

This is the issue with M1 MacBooks, Pasteboard is having this issue in latest chip and latest simulators.

As of now, no updates from apple for this. So we can try alternative something

•   Save what you want to paste into a textedit file 
•   Drag and drop the .txt file into the simulator window
•   The simulator will prompt you to Save the file in the Files App
•   From the Simulator Open the file and copy the text you want
•   Paste into your App

EXAMPLE: - Make sure to add yourfile.txt in your bundle. and here in textfield data will come from the file of your bundle. Even you can use file from document directory as well if you don't want to add file in bundle.

 func testExample() throws {
    
    let testBundle = Bundle(for: type(of: self))
    guard let filePath = testBundle.path(forResource: "yourfile", ofType: "txt") else {
        return
    }
    
    let fileURL = URL(fileURLWithPath: filePath)
    let result = try String(contentsOf: fileURL, encoding: .utf8)
    
    let app = XCUIApplication()
    app.launch()
    let textField = app.textFields["textFieldId"]
    textField.tap()
    textField.typeText(result)
    let resultLabel = app.staticTexts["resultId"]
    app.buttons["buttonId"].tap()
    XCTAssertEqual(textField.value as! String, resultLabel.label)
}

Since I've got my M1 in 2020 I could use copy/paste only in Xcode 11.x or lower. I did not find any settings for simulator or other checkboxes that could enable copy/paste again on Xcode 13

Just use simulator with iOS lower than 14. I personally prefer iPhone 11 (13.7)

This is unfortunately a recurring issue for a lot of people - no fix as of yet.

However there are three possible workarounds:

  1. If it is a link (or other supported data) you can right click (ctrl+click) within a macOS app (such as Safari or Mail) and select Share / Simulator from the context menu. This will open the URL in the Simulator you choose.
  2. Create a text file, save it to your Desktop, then drag it on top of your Simulator device. This will allow you to save it as a local file within the Simulator's iOS. You can then copy and paste any data from there by opening the text file from the Files app.
  3. Upload an HTML file to a server that is accessible by the simulator (could be on your localhost as well if you have Apache running) and open the link in Safari. Here's a php example that will allow you to click URLs or copy text easily.
Related