Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to make iOS Swift Playground Books Today

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

Lou Franco

September 07, 2016
Tweet

More Decks by Lou Franco

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. //#-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
  4. 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)
  5. 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
  6. 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