Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Xcode Extensions

Xcode Extensions

WWDC16で発表されたXcode Source Editor Extensionsの話

E4b19839ff3059133c51f097fbcd046c?s=128

Yoonchul Koh

June 23, 2016
Tweet

Transcript

  1. Xcode Extensions 2016/6/23 potatotips #30 @y_koh

  2. ࣗݾ঺հ • ߴ(͜͏) Ҹ⅑ • @y_koh • ҿ৯ళ޲͚༧໿୆ா
 τϨλ

  3. Xcode Extensions

  4. New Feature of Xcode 8

  5. Active Line Highlight

  6. Swift Color Literals

  7. Swift Image Literals

  8. Documentation Generation

  9. Xcode Source Editor Extensions

  10. How to Develop

  11. 1. File - New - Project… 2. OS X -

    Application - Cocoa Application 3. File - New - Target... 4. OS X - ApplicationExtensions - Xcode Source Editor Extension 5. Activate "APP_NAME" scheme?
  12. • SourceEditorExtension.swift • SourceEditorCommand.swift

  13. import Foundation import XcodeKit class SourceEditorExtension: NSObject, XCSourceEditorExtension { /*

    func extensionDidFinishLaunching() { // If your extension needs to do any work at launch, implement this optional method. } */ /* var commandDefinitions: [[XCSourceEditorCommandDefinitionKey: AnyObject]] { // If your extension needs to return a collection of command definitions that differs from those in its Info.plist, implement this optional property getter. return [] } */ }
  14. import Foundation import XcodeKit class SourceEditorCommand: NSObject, XCSourceEditorCommand { func

    perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void { // Implement your command here, invoking the completion handler when done. Pass it nil on success, and an NSError on failure. completionHandler(nil) } }
  15. import Foundation import XcodeKit class SourceEditorCommand: NSObject, XCSourceEditorCommand { func

    perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void { // ExtensionΛ࣮ߦͨ࣌͠ʹ։͍͍ͯΔϑΝΠϧ಺༰ // NSMutableArray - // __NSCFString, NSTaggedPointerString, ... for line in invocation.buffer.lines { debugPrint(line) } // ExtensionΛ࣮ߦͨ࣌͠ʹબ୒͍ͯ͠ΔҐஔ৘ใ // NSMutableArray - XCSourceTextRange for selection in invocation.buffer.selections { debugPrint(selection) } completionHandler(nil) } }
  16. import Foundation import XcodeKit class SourceEditorCommand: NSObject, XCSourceEditorCommand { func

    perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void { let lineCount = invocation.buffer.lines.count for i in 0...(lineCount-1) { let line = invocation.buffer.lines[i] let newLine = "\(String(line).trimmingCharacters(in: CharacterSet.newlines)) // " invocation.buffer.lines.replaceObject(at: i, with: newLine) } completionHandler(nil) } }
  17. How to Run

  18. 1. Target > My Mac - Run 2. Choose an

    app to run > Xcode Beta 3. Dark Xcode 4. Open Project 5. Menu > Editor > ProjectName > ExtensionName
  19. import Foundation import XcodeKit class SourceEditorCommand: NSObject, XCSourceEditorCommand { func

    perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void { let lineCount = invocation.buffer.lines.count for i in 0...(lineCount-1) { let line = invocation.buffer.lines[i] let newLine = "\(String(line).trimmingCharacters(in: CharacterSet.newlines)) // " invocation.buffer.lines.replaceObject(at: i, with: newLine) } completionHandler(nil) } }
  20. import Foundation // import XcodeKit // // class SourceEditorCommand: NSObject,

    XCSourceEditorCommand { // // func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: (NSError?) -> Void ) -> Void { // let lineCount = invocation.buffer.lines.count // for i in 0...(lineCount-1) { // let line = invocation.buffer.lines[i] // let newLine = "\(String(line).trimmingCharacters(in: CharacterSet.newlines)) // " // invocation.buffer.lines.replaceObject(at: i, with: newLine) // } // // completionHandler(nil) // } // // } //
  21. Summary • ࠓग़དྷΔ͜ͱ͸։͍͍ͯΔϑΝΠϧΛεΫϦϓτʹᷰΘͤͯԿ ͔Λॲཧ͢ΔɻඞཁͰ͋Ε͹݁ՌΛฦ͚ͩ͢ɻ • ͔͠͠ग़དྷΔ͜ͱ͕গͳ͗͢Δɻɻ • Swift Color LiteralsΈ͍ͨʹύϨοτΛදࣔͨ͠ΓɺΤσΟλͷ

    දࣔΛม͑Δ͜ͱ͸Ͱ͖ͳ͍ • Xcode editor extensionͱ͍͏ΤσΟλͷ֎ଆͷextension΋͋Δ Β͍͠ɻ͚ΕͲ৘ใݟ౰ͨΒͣɻɻ • ͱ͸͍͑ࠓޙ֦ॆ͞Ε͍ͯ͘ͱࢥ͏ͷͰΞοϓσʔτʹظ଴ʂ
  22. Reference • https://developer.apple.com/videos/play/ wwdc2016/414/ • Xcode Source Editor ExtensionΛࢼ͢
 http://qiita.com/_tid_/items/

    271c1973b3043f6c55cb • http://www.russbishop.net/xcode-extensions