Slide 1

Slide 1 text

EXTENDING XCODE MONITISE CREATE 2014 BORIS BÜGLING - @NEONACHO

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

CONTENTFUL

Slide 4

Slide 4 text

AGENDA ▸ Xcode ▸ Use plugins ▸ Develop your own plugin

Slide 5

Slide 5 text

APPCODE? .

Slide 6

Slide 6 text

XCODE

Slide 7

Slide 7 text

Plugins!

Slide 8

Slide 8 text

POSSIBILITIES ▸ Color Schemes ▸ File Templates ▸ Project Templates ▸ Plugins

Slide 9

Slide 9 text

USE PLUGINS

Slide 10

Slide 10 text

HOW DO I EVEN...

Slide 11

Slide 11 text

@_supermarin

Slide 12

Slide 12 text

ALCATRAZ The Xcode package manager http://alcatraz.io Marin, Delisa and Jurre

Slide 13

Slide 13 text

curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/ Scripts/install.sh | sh

Slide 14

Slide 14 text

opens

Slide 15

Slide 15 text

HOW DOES IT WORK? ▸ packages.json contains GitHub URL ▸ Clones the repository ▸ Runs xcodebuild with some parameters

Slide 16

Slide 16 text

SOME COOL PLUGINS

Slide 17

Slide 17 text

CLANGFORMAT

Slide 18

Slide 18 text

FUZZYAUTOCOMPLETE

Slide 19

Slide 19 text

KSIMAGENAMED

Slide 20

Slide 20 text

OMCOLORSENSE

Slide 21

Slide 21 text

POLYCHROMATIC

Slide 22

Slide 22 text

SHOWINGITHUB

Slide 23

Slide 23 text

VVDOCUMENTER-XCODE

Slide 24

Slide 24 text

XCODE_BEGINNING_OF_LINE

Slide 25

Slide 25 text

XCODECOLORS

Slide 26

Slide 26 text

DEVELOP YOUR OWN PLUGIN

Slide 27

Slide 27 text

GETTING STARTED ▸ Clone https://github.com/kattrali/Xcode5-Plugin-Template ▸ Put it into ~/Library/Developer/Xcode/Templates/Project Templates/Application Plug-in/Xcode5 Plugin.xctemplate

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

PLUGIN TEMPLATE ▸ Xcode 5.1 compatible ▸ Shows a menu item for testing ▸ On build, plugin ends up here: ~/Library/Application Support/ Developer/Shared/Xcode/Plug-ins/ ▸ Just restart and it shows up

Slide 30

Slide 30 text

ONCE YOU BUILD AND RESTART XCODE .

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

LET'S BUILD SOMETHING USEFUL... .

Slide 33

Slide 33 text

GENERAL POINTS

Slide 34

Slide 34 text

COMPATIBILITY UUIDS THIS MIGHT APPEAR IN YOUR SYSTEM.LOG [MT] PluginLoading: Required plug-in compatibility UUID 640F884E-CE55-4B40-87C0-8869546CAB7A for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPodsPlugIn.xcplugin' not present in DVTPlugInCompatibilityUUIDs $ defaults read /Applications/Xcode51-DP2.app/Contents/Info DVTPlugInCompatibilityUUID 640F884E-CE55-4B40-87C0-8869546CAB7A ADD THAT UUID TO YOUR PLUGIN'S INFO.PLIST

Slide 35

Slide 35 text

THIS WILL HAPPEN ALL THE TIME

Slide 36

Slide 36 text

YOUR ONLY FRIENDS... $ tail -f /var/log/system.log $ rm -rf ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/* ▸ Debug from the command line with lldb... ▸ or with a second instance of Xcode

Slide 37

Slide 37 text

HEADERS Use class-dump yourself, or just grab https://github.com/luisobo/Xcode5-RuntimeHeaders

Slide 38

Slide 38 text

WHAT WE ARE LOOKING FOR ▸ How to detect if the user types in the editor? ▸ How to hide the debug pane?

Slide 39

Slide 39 text

grep -ri editor *

Slide 40

Slide 40 text

@interface IDEWorkspaceWindowController : NSWindowController [...] @property(readonly) IDEEditorArea *editorArea; [...] @end

Slide 41

Slide 41 text

@interface IDEEditorArea : IDEViewController [...] - (void)toggleDebuggerVisibility:(id)arg1; - (void)activateConsole:(id)arg1; @property BOOL showDebuggerArea; [...] @end

Slide 42

Slide 42 text

- (void)toggleDebuggersIfNeeded { for (NSWindowController *workspaceWindowController in [objc_getClass("IDEWorkspaceWindowController") workspaceWindowControllers]) { id editorArea = [workspaceWindowController editorArea]; if ([editorArea showDebuggerArea]) { [editorArea toggleDebuggerVisibility:nil]; } } }

Slide 43

Slide 43 text

@interface NSObject (ShutUpWarnings) -(id)editorArea; -(BOOL)showDebuggerArea; -(void)toggleDebuggerVisibility:(id)arg; -(NSArray*)workspaceWindowControllers; @end

Slide 44

Slide 44 text

GREPPING THROUGH _SUBTREEDESCRIPTION grep -i source * [ AF O P LU ] h=--- v=--- NSClipView 0x7f822e93e990 f=(35,0,885,662) b=(0,637,-,-) TIME drawRect: min/mean/max 0.00/0.00/0.00 ms [ AF O LU ] h=-&- v=-&- DVTSourceTextView 0x7f822c723f00 f=(0,0,885,1339) b=(-) TIME drawRect: min/mean/max 0.00/0.00/0.00 ms [ A LU ] h=--- v=--- DVTMessageBubbleView 0x7f822eb5c080 f=(638,975,247,12) b=(-) TIME drawRect: min/mean/max 0.23/0.42/0.68 ms

Slide 45

Slide 45 text

DVTSourceTextView

Slide 46

Slide 46 text

- (void)swizzleDidChangeTextInSourceTextView { [[objc_getClass("DVTSourceTextView") new] yl_swizzleSelector:@selector(didChangeText) withBlock:^void(id sself) { [self toggleDebuggersIfNeeded]; [sself yl_performSelector:@selector(didChangeText) returnAddress:NULL argumentAddresses:NULL]; }]; }

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

@interface NSObject (YOLO) -(void)yl_performSelector:(SEL)aSelector returnAddress:(void *)result argumentAddresses:(void *)arg1, ...; -(void)yl_swizzleSelector:(SEL)originalSelector withBlock:(id)block; @end

Slide 50

Slide 50 text

- (void)swizzleDidChangeTextInSourceTextView { [[objc_getClass("DVTSourceTextView") new] yl_swizzleSelector:@selector(didChangeText) withBlock:^void(id sself) { [self toggleDebuggersIfNeeded]; [sself yl_performSelector:@selector(didChangeText) returnAddress:NULL argumentAddresses:NULL]; }]; }

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

SHIP IT { "name": "My Life-Changing Xcode Plugin", "url": "https://github.com/me/xcode-life-changing-plugin", "description": "Makes Xcode stop, collaborate and listen." } Send a pull request to the Alcatraz packages repo https://github.com/supermarin/alcatraz-packages

Slide 53

Slide 53 text

USING DTRACE ▸ Powerful dynamic tracing framework ▸ Can be used to log any objc_msgSend() ▸ Useful for seeing call trees of a specific class ▸ http://chen.do/blog/2013/10/22/reverse-engineering-xcode-with- dtrace/

Slide 54

Slide 54 text

THANK YOU!

Slide 55

Slide 55 text

https://github.com/kattrali/xcode-devtools https://coderwall.com/p/-mgtww https://github.com/neonichu/extending-xcode/ https://github.com/neonichu/BBUDebuggerTuckAway/ https://github.com/neonichu/BBUFullIssueNavigator/

Slide 56

Slide 56 text

alcatraz.io

Slide 57

Slide 57 text

http://vu0.org/alt14