繁体   English   中英

XCSourceEditorCommandInvocation快速扩展导致“无法识别的选择器发送到实例”异常

[英]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类,没有任何问题,所以我有点陷入困境。

我试过了:

  • 在方法声明之前添加@objc
  • 在扩展名和方法中添加public
  • 我没有扩展类集群,所以可能不是这个问题
  • 我没有扩展协议,所以可能不是这个问题

目前,XcodeKit.framework中的类或类型均不支持Objective-C类别或Swift扩展。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM