[英]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.