Swift Playgrounds and Swift Student Challenge 2021 — Part 1
Swift Student Challenge is a challenge for students aged 13 and above to submit a Swift Playground file with documentation. The scene in Swift Playground has to be interactive and must be experienced within three minutes. You can submit as long as it is an individual project (students below the age of 18 require parent/legal guardian contact information as well). With WWDC 21 announced, I decided to try it out.
Swift Playgrounds is meant for students and children to help them learn how to code in a fun way. I, however, learnt how to use Xcode before I learnt how Swift Playgrounds work. The first coding experience I had as a kid was Logo-Turtle which was essentially a triangle (the turtle) that moved around when commands were given to it.
I believe Playgrounds can be built directly on Swift Playgrounds (MacOS Application) and on the iPad version (iOS Application) as well. Initially, I decided to try it out on Xcode, since it could build Playgrounds as well, but then eventually decided to try out Swift Playgrounds on MacOS, which you will see as you read on.
1. Creating a Playground on Xcode :
The first sample that Xcode generally shows is a simple display of “Hello, playground” as seen in the screenshot below.
I played around with it a little bit until I this popped up — error : No such module ‘UIKit’
I tried removing the UIKit module to see what would happen, and as expected, it couldn’t find UIHostingController in scope.
At this point, an article on the internet came to my rescue (as always) by showing one simple solution, changing the platform to iOS found on Playground Settings.
Now this was just a sample code I ran on Xcode, but I was still curious on what Swift Playgrounds could do since I heard previously from a lecturer that it was more language specific and that Xcode is used for building Playgrounds when you want to work with libraries such as UIKit. So I gave in and downloaded Swift Playgrounds to finally try it out.
2. Creating Playgrounds using the given Templates :
Now one of the major features from Swift Playgrounds that make it easy to code is that they already have ready-made templates to choose from. The one I chose to play around with was the Shapes template (see video below)
I tried playing around with this template and of all the things that I could’ve possibly created with this template, I created an Animal Farm of animals that performed backflips (*insert laughs/applause, either works*).
I used emojis and clip art for the graphics, but why is there a monkey in the farm when most other animals are domesticated? I don’t know, don’t ask.
3. Creating Playgrounds using a Blank Template:
I finally began working on a blank playground file and decided to go with a YouTube tutorial at first with the reference of which, I wrote the code to display a simple circle with animation that changes color on tap.
Since the code ran smooth with no trouble, I decided that my lucky streak had to be jinxed. Which is why I tried a code on Augmented Reality since I’ve only seen those coded on an iOS interface and not a MacOS.
The library I used for Augmented Reality here was ARKit and Apple provides adequate documentation if you want to take a look at it.
On running the code however, even though the code showed no error, there was no camera input. I could have looked more into it, but I did not have the time as I had to rush through to get my submission ready.
If the code had worked, it would have displayed a blue water bubble on a horizontal surface by taking inputs from the device camera.
This article by itself is slightly longer than what my original idea was, so I’ll be writing a second part to this which will be linked below as soon as I publish it. The second part will be more specific to my WWDC 21 submission.
Note: This article is not sponsored and is purely based on the author’s opinions and personal experience on the journey of learning. None of the links provided here are affiliate links and are provided only for the purpose of learning.
The author is a student completing an Engineering Degree in Computer Science with Specialization in Cloud Technology and Mobile Applications.
Check out this article on my Personal Blog : Swift Playgrounds and Swift Student Challenge 2021 — Part 1