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

How to make iOS Swift Playground Books Today

E27f554e9ed800bca61642acaba29452?s=47 Lou Franco
September 07, 2016

How to make iOS Swift Playground Books Today

This was a lightning talk at iOSDevUK 2016. It describes playground books and some authoring tools. More info here: http://loufranco.com/blog/iosdevuk-lightning-talk-about-swift-playground-books and here: http://loufranco.com/blog/authoring-an-ios-swift-playground-book

E27f554e9ed800bca61642acaba29452?s=128

Lou Franco

September 07, 2016
Tweet

Transcript

  1. Playground Books How to make them today

  2. None
  3. None
  4. None
  5. None
  6. None
  7. None
  8. How to make a book right now

  9. playgroundbook github.com/ashfurrow/playgroundbook $ playgroundbook render MyBook.yaml $ playgroundbook lint MyBook.playgroundbook

    Validating MyBook.playgroundbook/...
  10. Playground books support a rich set of awesome features to

    make learning how to code really easy, and this tool uses almost none of them. — Ash Furrow
  11. My Goal 1. Write the code in Xcode 2. Build

    it there too 3. Run it in a host app 4. Unit-test the playground and LiveView code
  12. //#-hidden-code import PlaygroundSupport private func ask(_ attribute: ShapeAttribute) { let

    page = PlaygroundPage.current if let proxy = page.liveView as? PlaygroundRemoteLiveViewProxy { let dict = PlaygroundValue.dictionary([ "method": .string("ask"), "attribute": .integer(attribute.rawValue) ]) proxy.send(dict) } } //#-end-hidden-code
  13. PlaygroundSupportMock github.com/loufranco/PlaygroundSupportMock 1. Implements PlaygroundValue and the messaging prototypes 2.

    Lets you build, but doesn't actually do anything yet
  14. None
  15. None
  16. pgbookc github.com/loufranco/pgbookc 1. File renaming 2. Special comments

  17. Playground code //#-hidden-code import PlaygroundSupport let cloud = Shapes[5] //#-end-hidden-code

    func hasAttribute(shape: Shape, attribute: ShapeAttribute) -> Bool { let attributes: Set<ShapeAttribute> = shape.attributes return attributes.contains(attribute) } hasAttribute(shape: cloud, attribute: .IsGray)
  18. App code //#-hidden-code import PlaygroundSupport let cloud = Shapes[5] //#-end-hidden-code

    func hasAttribute(shape: Shape, attribute: ShapeAttribute) -> Bool { let attributes: Set<ShapeAttribute> = shape.attributes return attributes.contains(attribute) } func Contents0102() -> Bool { return // REMOVE LINE hasAttribute(shape: cloud, attribute: .IsGray) } // REMOVE LINE
  19. You can Unit Test! func testContents0102() { XCTAssert(Contents0102()) }

  20. ShapeSearch github.com/loufranco/ShapeSearch 1. Book to teach binary search 2. Builds

    in a host app 3. Uses PlaygroundSupportMock and pgbookc 4. Can run LiveViews and unit test Playgrounds
  21. None
  22. None
  23. None
  24. None
  25. None
  26. Thanks Get links on http://loufranco.com