DocC for Building Tutorials

One of my favorite things from WWDC21 this year was the DocC stuff. The funny thing is, I had NO IDEA it would be one of my favorites until Saturday, when I was catching up on some sessions.

There are the heavy hitters, of course, like the SwiftUI sessions, the announcement that you’ll be able to build and submit apps to the App Store from the next version of Swift Playgrounds. But this was a sneaky, wonderful surprise.

But go check out Building Interactive Tutorials with DocC. That’s an amazing session that I, as someone who tries to teach coding, found incredibly useful. You can build tutorials like the ones for SwiftUI and App Dev Training that Apple have shipped.

Build Your Own

That’s a good start, building rich tutorials that show up in the Xcode documentation window. Buuuuuuut, if you check out Host and automate your DocC documentation, you’ll see that you can put it up on your own site!

You need Xcode 13, the beta, to build documentation, but your students don’t. You can export the DocC archive, put it up on a website, and away you go!

Now, it was a bit more work than just “upload it to a website and you’re good to go.” I’ll go into the details of what you need to do, from a practical standpoint, in the future.

But for now, you can now browse the start of a series of tutorials all centered around the QuestionBot.

It’s a Swift package based around a QuestionBot type. The tutorial series takes you through building the QuestionBot as a command-line tool in replit.com, then using UIKit to build the project you see in Develop in Swift Explorations, then, finally, the SwiftUI implementation you may have seen (or will see) in our Teaching Develop in Swift Online class!

At the moment, there’s only the first tutorial, the others are coming soon. But I love the UI for the tutorials and how much easier it was to throw it together this way.

There’s also a really nice, comprehensive documentation page where you can check out the API for QuestionBot and still navigate to the tutorials to see how you might use that code in practice.

Like I said, I’ll detail how I built that tutorial in a future post, but in the meantime you can see the results. It’s rare we get to ship stuff they just announce at WWDC, and ‘m so psyched about writing some more tutorials and having them look excellent out of the gate!

WWDC Favorites?

I hope you’re all enjoying WWDC21 so far!

There’s so much to chew on, from SwiftUI improvements and additions, Xcode Cloud, RealityKit additions, Object Capture, Accessibility. AND BUILDING APPS IN SWIFT PLAYGROUNDS!

But I’d love to hear from you, what is the most exciting technology or thing they’re highlighting at WWDC this year?

Who knows, this might help us add things you care about to Teaching Develop in Swift Online in two weeks!

Build your own QuestionBot

Happy WWDC! It’s that magical time of year when developers working on Apple platforms have all their dreams come true!

Well, okay, maybe not, but we get a very fun week of new tech and demos and excitement about the platform.

If you’re watching all of this (or watching the people watching it and wondering what the heck is all the fuss about), we’ll probably have some words about it this week. But before that all kicks off, I threw a little playground up for you to experiment with, especially if you’re new to Swift, Apple’s programming language for iPhone, iPad, Mac, Apple Watch, and AppleTV apps.

QuestionBot

There’s a really fun exercise in Develop in Swift Explorations called QuestionBot. In it, you build the brains of an app to answer whatever question a person might type in. You can make it super complicated, or very, very simple.

We use this exercise during our Teaching Develop in Swift online class, and it’s usually impressive how different the apps can be.

Well, now, even if you don’t have a Mac, you can play around with QuestionBot. I created a REPL on replit.com with some simple instructions so that you, too, can create a functioning QuestionBot. Try it out:

http://replit.com/@mhanlon9/questionbot

There are two files, just tap on the Code tab and you’ll see main.swift and QuestionBot.swift.

Those show you the brains of our app.

The fork button

If you want to edit the code, just tap on the Fork button, which will create a copy of the code. You need to create a free replit.com account or link it to your Google, Github, or Facebook account, if you have one.

If you want to change QuestionBot’s behavior: how it asks questions and how it answers them, look in the QuestionBot.swift file.

If you want to change something else about the program, maybe limit it to only allowing you to ask three questions, or only letting people ask it questions on a Thursday, you would edit the main.swift file.

Coding for All

I really like replit.com because you can use it with any device, and it’s a great way to get an introduction to Swift before jumping in with an iPad or Mac.

I’ll be recording a short video introducing the QuestionBot on replit.com in the near future, but in the meantime, good luck coding!

The Code Hub: Adventures! New Swift Playgrounds

Inspired by some recent teacher questions via email and Twitter, I threw together some more advanced Swift Playgrounds.

Adventures!

Right now there are two of them. As Swift Playgrounds, they’re designed to run in the Playgrounds app on your iPad, so you can take your code on the go with you, or monkey around with them in the Playgrounds app on your Mac. Playgrounds is a great environment for tinkering with code and it just keeps getting better and better.

I split them into a separate feed from our normal playground feed because the original is aimed at beginners, learning to code. This new set of playgrounds comes with fewer instructions and tackles more complex material.

Add the feed from our playgrounds page, if you’re on an iPad. If you’re using Playgrounds on a Mac, you can select File > Add Subscription… and add this URL: https://www.thecodehub.ie/playgrounds/adventures/feed.json

SwiftUI

The first playground tackles the @StateObject and ObservableObjects in SwiftUI, “the new hotness,” as my old boss would say.

In this playground, we use new files in the UserModule to create a model that will hold minutes for a timer (seconds, really)… we show you how to organize your code to keep the “model” in one place that you could use from multiple locations in your SwiftUI-based app.

UIView and Animation

The second playground shows off creating a UIView in code, making it the live view and animating an image view across the screen.

It’s a nice way to start playing with animation and checking out all the properties you can animate on a UIView.

More to Come

There are more to come, of course, this is just the start. Hopefully these playgrounds will give you an idea for what you can do with the Playgrounds app. Post-WWDC, I’m sure, we’ll have lots more goodies to explore all the fun new toys we have to play with.

So check them out and try your hand with some Swift code on the go!