[英]XCSourceEditorCommandInvocation swift extension causes “unrecognized selector sent to instance” exception
When I try and add swift extensions to classes in XcodeKit
(framework for adding Xcode extensions) the compiler is happy to build without any errors, but when the code runs I get the following exception: 当我尝试向
XcodeKit
类添加快速扩展(用于添加Xcode扩展的框架)时,编译器很乐意构建而没有任何错误,但是当代码运行时,出现以下异常:
-[XCSourceEditorCommandInvocation test]: unrecognized selector sent to instance 0x7fc60543f2b0
Below is sample code which can reproduce the exception: 下面是可以重现异常的示例代码:
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!")
}
}
I've extended ObjC classes in swift in the past without any issues so I'm a bit stuck here. 过去,我迅速扩展了ObjC类,没有任何问题,所以我有点陷入困境。
I've tried: 我试过了:
@objc
before the method declaration. @objc
。 public
to the extension and method. public
。 目前,XcodeKit.framework中的类或类型均不支持Objective-C类别或Swift扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.