当我尝试在XcodeKit (用于添加Xcode扩展的框架)中的类中添加快速扩展时,编译器很乐意构建而不会出现任何错误,但是当代码运行时,我会得到以下异常:
-[XCSourceEditorCommandInvocation test]: unrecognized selector sent to instance 0x7fc60543f2b0下面是可以再现异常的示例代码:
class SourceEditorCommand: NSObject, XCSourceEditorCommand {
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void {
// Call extension method
invocation.test() // <--- Exception thrown here
completionHandler(nil)
}
}
extension XCSourceEditorCommandInvocation {
func test() {
print("it works!")
}
}在过去,我在没有任何问题的情况下迅速地扩展了ObjC类,所以我被困在这里了。
我试过:
@objc。public添加到扩展和方法中。发布于 2018-02-03 20:35:30
此时XcodeKit.framework中的类或类型既不支持Objective类别,也不支持Swift扩展。
https://stackoverflow.com/questions/41288706
复制相似问题