我創建了一個定製的Xcode編輯器擴展,如果某些條件未得到滿足,它可能無法運行。Xcode不顯示來自自定義編輯器擴展的錯誤文本
具體來說,這是一個Sort Lines命令,如果有多個選擇,或者選擇的行少於兩行,它將拒絕運行。
我已經定義了符合錯誤的枚舉來定義我也符合LocalizedError的錯誤。
enum CommandError: Error, LocalizedError
{
case notEnoughLines
case tooManySelections
public var errorDescription: String?
{
switch self
{
case .notEnoughLines: return NSLocalizedString("Not enough lines to sort", comment: "notEnoughLines")
case .tooManySelections: return NSLocalizedString("Too many selections", comment: "tooManySelections")
}
}
}
在我執行(附:completionHandler :)我稱之爲完成處理器與錯誤之一是適當的:
...
if invocation.buffer.selections.count > 1
{
completionHandler(CommandError.tooManySelections)
return
}
...
我期待在錯誤的文本(「太多的選擇「)被顯示。相反,錯誤顯示爲:
該操作無法完成。 (Ext01.SortLinesCommand.CommandError錯誤1)
上午我錯誤地這樣做,或者這是XcodeKit或Xcode中的問題嗎?
謝謝你。我會在下次啓動Xcode時嘗試它(目前正在處理其他內容)。 –