Save 37% off PRO during our Black Friday Sale! »

💥 Custom Playgrounds 🎯

💥 Custom Playgrounds 🎯

How to use custom frameworks in Playgrounds in Xcode 6 beta 2. Look at the internals of Playgrounds and how BBUToyUnboxer was implemented. Given at SwiftCrunch 2014 in Krakow.

9d2ea021919ff81e02d48530aae191bd?s=128

Boris Bügling

July 06, 2014
Tweet

Transcript

  1. ! CUSTOM PLAYGROUNDS " SWIFTCRUNCH, JULY 2014 BORIS BÜGLING -

    @NEONACHO
  2. None
  3. COCOAPODS - CONTENTFUL

  4. SWIFT?

  5. SWIFT!

  6. REPL

  7. $ swift Welcome to Swift! Type :help for assistance. 1>

    import ContentfulDeliveryAPI <REPL>:1:8: error: no such module 'ContentfulDeliveryAPI' import ContentfulDeliveryAPI ^
  8. Copy your framework over to /Applications/Xcode6-Beta2.app/ Contents/Developer/Platforms/MacOSX.platform/Developer/ SDKs/MacOSX10.10.sdk/System/Library/Frameworks

  9. 1> import ContentfulDeliveryAPI 2> var client = CDAClient() client: CDAClient

    = <extracting data from value failed> error: Couldn't lookup symbols: _OBJC_CLASS_$_CDAClient
  10. LOAD THE DYNAMIC LIBRARY FROM YOUR FRAMEWORK USING dlopen()

  11. 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 = {}
  12. SUCCESS

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

  14. None
  15. None
  16. 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
  17. None
  18. SAM MARSHALL

  19. None
  20. XCODE PLUGIN?

  21. None
  22. 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 (?)
  23. ¯\_()_/¯

  24. None
  25. None
  26. ➡️ XCODE PLUGIN

  27. LIBPLAYGROUNDINJECTOR.DYLIB

  28. #import <IDELanguageSupportUI/IDEPlaygroundExecutionDeviceService.h> @interface IDELocalComputerPlaygroundExecutionDeviceService : IDEPlaygroundExecutionDeviceService + (id)capability; - (id)sessionForExecutingPlaygroundWithParameters:(id)arg1;

    - (id)defaultStubPathForSDK:(id)arg1; @end
  29. DYLD_INSERT_LIBRARIES

  30. @interface IDEPlaygroundExecutionSession : NSOperation [...] - (void)cleanupExecutable; - (void)destroyDebugger; -

    (void)_stopListeningForPlaygroundInput; - (void)_interruptExecutingPlaygroundSource; - (void)cancel; - (BOOL)canFinishExecution; [...] @end
  31. @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
  32. None
  33. SOURCEKIT

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

  35. 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 = ...; }
  36. IDESourceLangaugeServiceContextBuildSettings

  37. IDESourceLangaugeServiceContextBuildSettings

  38. ( 

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

  40. None
  41. import XCPlayground XCPSetExecutionShouldContinueIndefinitely()

  42. None
  43. DEMO

  44. None
  45. RELEVANT WWDC 2014 SESSIONS ▸ Session 408: Swift Playgrounds ▸

    Session 409: Introduction to LLDB and the Swift REPL
  46. 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

  47. THANK YOU!

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

  49. IT'S A ZERO!