复制/粘贴不使用M1 Macbook Pro模拟器的Xcode 13。它在正常的Mac电脑上工作。
这就是M1 MacBooks的问题所在,在最新的芯片和最新的模拟器中都有这个问题。
到目前为止,苹果公司还没有更新这方面的信息。所以我们可以尝试其他的方法
• 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
示例:-确保在包中添加
yourfile.txt
。这里,在textfield中,数据将来自包的文件。如果不想在包中添加文件,甚至可以使用文档目录中的文件。
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"]