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:
-[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.
I've tried:
@objc
before the method declaration. public
to the extension and method. 目前,XcodeKit.framework中的类或类型均不支持Objective-C类别或Swift扩展。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.