Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XCSourceEditorCommandInvocation swift扩展名原因“;已将无法识别的选择器发送到实例";例外_Swift_Swift Extensions_Xcode Extension - Fatal编程技术网

XCSourceEditorCommandInvocation swift扩展名原因“;已将无法识别的选择器发送到实例";例外

XCSourceEditorCommandInvocation swift扩展名原因“;已将无法识别的选择器发送到实例";例外,swift,swift-extensions,xcode-extension,Swift,Swift Extensions,Xcode Extension,当我尝试向XcodeKit(用于添加Xcode扩展的框架)中的类添加swift扩展时,编译器很乐意构建,没有任何错误,但当代码运行时,我得到以下异常: -[XCSourceEditorCommandInvocation test]: unrecognized selector sent to instance 0x7fc60543f2b0 class SourceEditorCommand: NSObject, XCSourceEditorCommand { func perform(

当我尝试向
XcodeKit
(用于添加Xcode扩展的框架)中的类添加swift扩展时,编译器很乐意构建,没有任何错误,但当代码运行时,我得到以下异常:

-[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!")
    }
}
下面是可以重现异常的示例代码:

-[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!")
    }
}
类SourceEditorCommand:NSObject,xSourceEditorCommand{
func-perform(调用:XCSourceEditorCommandInvocation,completionHandler:@escaping(Error?->Void)->Void{
//呼叫扩展方法

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