我正在尝试在XCTest没有代码签名的情况下运行在框架中编写的多个测试,目的是不必处理在 CI 上导入代码签名身份的麻烦。
我已经删除了开发团队,并将应用程序和测试目标的签名证书设置为“签名以在本地运行”。建筑与
xcodebuild build-for-testing -scheme <my scheme>
Run Code Online (Sandbox Code Playgroud)
适用于 CI 和本地,但尝试运行测试
xcodebuild test-without-building -scheme <my scheme>
Run Code Online (Sandbox Code Playgroud)
大约 10 秒后失败并出现错误<name> (83559) encountered an error (Failed to load the test bundle.。<test binary> not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?下面几行可以更清楚地说明这个问题。似乎 macOS 不喜欢未签名的测试包并拒绝加载它。
像这样运行测试命令:
xcodebuild test-without-building -xctestrun /Users/vinkwok/Library/Developer/Xcode/DerivedData/ChessFrontend-carjpisbuprsabeulpsycoxjqjea/Build/Products/ChessFrontend_macosx13.0-arm64.xctestrun -destination "platform=macOS,id=<id>,arch=arm64"
Run Code Online (Sandbox Code Playgroud)
抛出以下错误:
Early unexpected exit, operation never finished bootstrapping …Run Code Online (Sandbox Code Playgroud) 我正在尝试在文本框中处理换行符的shift+enter(聊天应用程序例如WhatsApp、Discord 等实现)。目前,我正在使用 SwiftUI TextEditor,但它没有任何方法可以像在 AppKit 中那样处理原始键盘事件。因此,一个黑客解决方案是检查消息的最后一个字符是否是 .onchange 中的换行符,然后发送消息。这种方法适用于“输入发送”,但我找不到在按下 Shift 键时不发送消息的方法(对于多行消息)。
我正在尝试一种使用NSViewRepresentableAppKit API 的方法,如下所示:
struct KeyEventHandling: NSViewRepresentable {
class KeyView: NSView {
override var acceptsFirstResponder: Bool { true }
override func keyDown(with event: NSEvent) {
print("keydown event")
}
override func flagsChanged(with event: NSEvent) {
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
case [.shift]:
print("shift key pressed")
default:
print("no modifier keys are pressed")
}
}
}
func makeNSView(context: Context) -> NSView {
let view = KeyView()
DispatchQueue.main.async { // wait till next event …Run Code Online (Sandbox Code Playgroud) 我有一个相当大的结构,符合Codable,并且它的属性之一需要与其本身具有相同的类型。我正在尝试做的事情的简短示例如下所示:
struct Message: Codable {
let content: String
// ...other values
let reference: Message // <-- Error: Value type 'Message' cannot have a stored property that recursively contains it
}
Run Code Online (Sandbox Code Playgroud)
Swift 似乎不允许结构体递归地将自身包含为其值之一。Message除了创建一个完整的重复结构(这会将其变成先有鸡还是先有蛋的问题,其中重复结构不能包含自身等)之外,还有什么方法可以使其工作吗?不创建重复的结构还允许我重用接收和呈现Message结构的 SwiftUI 代码。
我正在 C++ 11 中编写一个实用函数,它将单一类型的元素添加到向量中。我发现的大多数变量参数文档/指南都显示了带有该typedef类型的模板,但我希望仅允许所有变量参数使用单一类型(const char*)。以下是相关代码片段:
项目.hpp:
// Guard removed
#include <vector>
class Item {
public:
Item(const char* n, bool (*optionChange)(uint8_t), const char*...);
private:
std::vector<const char*> options;
void addOption(const char*);
}
Run Code Online (Sandbox Code Playgroud)
项目.cpp:
#include "Item.hpp"
void Item::addOption(const char* option) {
options.push_back(option);
}
Item::Item(
const char* n,
bool (*optionChange)(uint8_t),
const char* opts...
): name(n), type(MENU_TYPE_OPTS), selectedOpt(0) {
addOption(opts...); // Doesn't compile
}
Run Code Online (Sandbox Code Playgroud)
上述代码的编译失败并显示消息error: expansion pattern 'opts' contains no argument packs。