Slide 1

Slide 1 text

! CUSTOM PLAYGROUNDS " SWIFTCRUNCH, JULY 2014 BORIS BÜGLING - @NEONACHO

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

COCOAPODS - CONTENTFUL

Slide 4

Slide 4 text

SWIFT?

Slide 5

Slide 5 text

SWIFT!

Slide 6

Slide 6 text

REPL

Slide 7

Slide 7 text

$ swift Welcome to Swift! Type :help for assistance. 1> import ContentfulDeliveryAPI :1:8: error: no such module 'ContentfulDeliveryAPI' import ContentfulDeliveryAPI ^

Slide 8

Slide 8 text

Copy your framework over to /Applications/Xcode6-Beta2.app/ Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.10.sdk/System/Library/Frameworks

Slide 9

Slide 9 text

1> import ContentfulDeliveryAPI 2> var client = CDAClient() client: CDAClient = error: Couldn't lookup symbols: _OBJC_CLASS_$_CDAClient

Slide 10

Slide 10 text

LOAD THE DYNAMIC LIBRARY FROM YOUR FRAMEWORK USING dlopen()

Slide 11

Slide 11 text

3> var handle = dlopen("/Applications/.../Versions/A/ContentfulDeliveryAPI", 2) handle: COpaquePointer = Builtin.RawPointer = 0x0000000102e2b6e0 -> 0x00007fff5fc37e50 vtable for ImageLoaderMachOCompressed + 16 4> var client = CDAClient() client: CDAClient = {}

Slide 12

Slide 12 text

SUCCESS

Slide 13

Slide 13 text

// Playground - noun: a place where people can play

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

24/06/14 01:00:00,780 Xcode[84816]: IDEPlaygroundExecutionSessionThread(pid=85188) IDEPlaygroundExecution: [PlaygroundSession <0x7fff12750c70>] Received error from expr: error: error: Couldn't lookup symbols: _OBJC_CLASS_$_CDAClient

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

SAM MARSHALL

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

XCODE PLUGIN?

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

DVTPLAYGROUNDCOMMUNICATION.FRAMEWORK @interface DVTPlaygroundCommunicationListener { NSString *_socketPath; } @interface DVTPlaygroundCommunicationSender ▸ Uses TCP/IP on the local machine to communicate between Stub and Xcode ▸ But apparently uses Unix domain sockets for the other direction (?)

Slide 23

Slide 23 text

¯\_()_/¯

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

➡️ XCODE PLUGIN

Slide 27

Slide 27 text

LIBPLAYGROUNDINJECTOR.DYLIB

Slide 28

Slide 28 text

#import @interface IDELocalComputerPlaygroundExecutionDeviceService : IDEPlaygroundExecutionDeviceService + (id)capability; - (id)sessionForExecutingPlaygroundWithParameters:(id)arg1; - (id)defaultStubPathForSDK:(id)arg1; @end

Slide 29

Slide 29 text

DYLD_INSERT_LIBRARIES

Slide 30

Slide 30 text

@interface IDEPlaygroundExecutionSession : NSOperation [...] - (void)cleanupExecutable; - (void)destroyDebugger; - (void)_stopListeningForPlaygroundInput; - (void)_interruptExecutingPlaygroundSource; - (void)cancel; - (BOOL)canFinishExecution; [...] @end

Slide 31

Slide 31 text

@interface IDEPlaygroundExecutionParameters : NSObject [...] - (id)initWithSourceCodeToExecute:(id)arg1 documentFileURL:(id)arg2 documentContentTimestamp:(id)arg3 autoTerminationDelay:(unsigned long long)arg4 executionPreparationParameters:(id)arg5 playgroundReportResultBlock:(id)arg6 playgroundExecutionWillFinishBlock:(void)arg7 playgroundExpressionCompleteBlock:(id)arg8 errorHandlerBlock:(void)arg9; @end

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

SOURCEKIT

Slide 34

Slide 34 text

@interface IDESourceLanguageServiceSwift : DVTSourceLanguageService [...] - (void)_applyChangesFromSourceLanguageServiceContext:(id)arg1; [...] @end

Slide 35

Slide 35 text

05/07/14 09:43:08,109 Xcode[9202]: toy-unboxing -- Fixed context: { DVTSourceLanguageServiceContextFormatOptionsKey = { ... }; DVTSourceLanguageServiceContextTextStorage = ...; IDESourceLangaugeServiceContextBuildSettings = { swiftASTCommandArguments = ( "-module-name", Playground, "-target", "x86_64-apple-macosx10.10", "-sdk", "/Applications/Xcode6-Beta2.app/.../MacOSX10.10.sdk", "-F", "/Applications/Xcode6-Beta2.app/.../Frameworks", "-F", "/Applications/Xcode6-Beta2.app/.../PrivateFrameworks", "-Xfrontend", "-debugger-support", "-c", "/Users/boris/Desktop/MyPlayground.playground" ); }; IDESourceLanguageServiceContextDocument = ...; IDESourceLanguageServiceContextDocumentURL = ...; }

Slide 36

Slide 36 text

IDESourceLangaugeServiceContextBuildSettings

Slide 37

Slide 37 text

IDESourceLangaugeServiceContextBuildSettings

Slide 38

Slide 38 text

( 

Slide 39

Slide 39 text

[...] "-F", "/Users/boris/Library/Developer/Playground Frameworks", [...]

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

import XCPlayground XCPSetExecutionShouldContinueIndefinitely()

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

DEMO

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

RELEVANT WWDC 2014 SESSIONS ▸ Session 408: Swift Playgrounds ▸ Session 409: Introduction to LLDB and the Swift REPL

Slide 46

Slide 46 text

LINKS ▸ http://samdmarshall.com/blog/ custom_frameworks_and_swift.html ▸ https://github.com/jas/swift-playground-builder ▸ http://stackoverflow.com/questions/24058336/how-do-i-run- asynchronous-callbacks-in-playground

Slide 47

Slide 47 text

THANK YOU!

Slide 48

Slide 48 text

HTTP://VU0.ORG/PLAYGROUNDS HTTP://VU0.ORG/ALT14 @NEONACHO

Slide 49

Slide 49 text

IT'S A ZERO!