My talk at Mobile Era conference 2018 in Oslo
From Xcode plugin to Xcodeextension
View Slide
AboutKhoa Phamgithub.com/onmyway133github.com/hyperoslomedium.com/@onmyway133
It takes 2 iOS developersto start complaining aboutXcode
XcodeWay
Xcode plugin
Alcatraz
XVim
SCXcodeMiniMap
FuzzyAutocompletePlugin
ColorSense-for-Xcode
Techniques• Private frameworks• Objective C Runtime• LLDB• Swizzling
class-dump• IDEKit• DVTKit• Xcode.app/Contents/SharedFrameworks/DVTKit.framework
DVTBezelAlertPanelclass func swizzleMethods() {guard let originalClass = NSClassFromString("DVTBezelAlertPanel") as? NSObject.Type else {return}do {try originalClass.jr_swizzleMethod("initWithIcon:message:parentWindow:duration:",withMethod: "xmas_initWithIcon:message:parentWindow:duration:")}catch {Swift.print("Swizzling failed")}}
DVTSourceTextViewfunc listenNotification() {NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(handleSelectionChange(_:)),name: NSTextViewDidChangeSelectionNotification, object: nil)}func handleSelectionChange(note: NSNotification) {guard let DVTSourceTextView = NSClassFromString("DVTSourceTextView") as? NSObject.Type,object = note.object where object.isKindOfClass(DVTSourceTextView.self),let textView = object as? NSTextViewelse { return }self.textView = textView}
IDEWorkspaceWindowControllerself.IDEWorkspaceWindowControllerClass =objc_getClass("IDEWorkspaceWindowController");NSArray *workspaceWindowControllers =[self.IDEWorkspaceWindowControllerClassvalueForKey:@"workspaceWindowControllers"];
XcodeGhost
Xcode Source Editor extension• Modify contents• Modify current text selection• Seperated processprotocol XCSourceEditorCommand {func perform(with invocation: XCSourceEditorCommandInvocation,completionHandler: @escaping (Error?) -> Void)}
App Extension• Share• Photo Editing• Today• Finder Sync• Custom Keyboard• File Provider• Document Provider
Resigncodesign
XcodeColorSense extension ?• No Notification• No UI modification
Color literal!#colorLiteral
XcodeWay extension ?• No NSTask• No NSWorkspace• No swizzling
AppleScript!
• NSUserAppleScriptTask• NSAppleEventDescriptor• ProcessSerialNumberon myOpenFolder(myPath)tell application "Finder"activateopen myPath as POSIX fileend tellend myOpenFolder
App Sandbox
Scripts DirectoryNSApplicationScriptsDirectory
macOS Mojave• WWDC 2018 - Your Apps and the Future of macOS Security• NSAppleEventsUsageDescription
• https://github.com/onmyway133/XcodeWay• https://github.com/onmyway133/XcodeColorSense2• https://github.com/theswiftdev/awesome-xcode-extensions
ThanksMay your code continue to compile