Share
Embed
Transcript
22 slides
-
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? -
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 [] } */ } -
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) } } -
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) } } -
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) } } -
1. Target > My Mac - Run 2. Choose an
app to run > Xcode Beta 3. Dark Xcode 4. Open Project 5. Menu > Editor > ProjectName > ExtensionName -
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) } } -
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) // } // // } // -
Summary • ࠓग़དྷΔ͜ͱ։͍͍ͯΔϑΝΠϧΛεΫϦϓτʹᷰΘͤͯԿ ͔Λॲཧ͢ΔɻඞཁͰ͋Ε݁ՌΛฦ͚ͩ͢ɻ • ͔͠͠ग़དྷΔ͜ͱ͕গͳ͗͢Δɻɻ • Swift Color LiteralsΈ͍ͨʹύϨοτΛදࣔͨ͠ΓɺΤσΟλͷ
දࣔΛม͑Δ͜ͱͰ͖ͳ͍ • Xcode editor extensionͱ͍͏ΤσΟλͷ֎ଆͷextension͋Δ Β͍͠ɻ͚ΕͲใݟͨΒͣɻɻ • ͱ͍͑ࠓޙ֦ॆ͞Ε͍ͯ͘ͱࢥ͏ͷͰΞοϓσʔτʹظʂ -
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