[英]XCSourceEditorCommandInvocation swift extension causes “unrecognized selector sent to instance” exception
当我尝试向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类,没有任何问题,所以我有点陷入困境。
我试过了:
目前,XcodeKit.framework中的类或类型均不支持Objective-C类别或Swift扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.