Skip to content

Instantly share code, notes, and snippets.

@dolphinsue319
Created September 10, 2016 12:24
Show Gist options
  • Save dolphinsue319/fa552a6fe18b210ca70730476e73df92 to your computer and use it in GitHub Desktop.
Save dolphinsue319/fa552a6fe18b210ca70730476e73df92 to your computer and use it in GitHub Desktop.
Sample of SourceEditorCommand.swift
import Foundation
import XcodeKit
class SourceEditorCommand: NSObject, XCSourceEditorCommand {
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void {
// Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure.
print("command identifier: \(invocation.commandIdentifier)")
print("content UTI: \(invocation.buffer.contentUTI)")
print("tab width: \(invocation.buffer.tabWidth)")
print("indentation width: \(invocation.buffer.indentationWidth)")
print("is use tab for indentation: \(invocation.buffer.usesTabsForIndentation)")
print("lines (strings in each line): \(invocation.buffer.lines)")
print("selections (array of XCSourceTextRange): \(invocation.buffer.selections)")
print("completeBuffer: \(invocation.buffer.completeBuffer)")
let error = NSError(domain: "the Domain", code: 60, userInfo: nil)
completionHandler(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment