Mastering SwiftUI Development by Building Pomodoro Tracker — Step 2: Hello World Swift!

Eko Suprapto Wibowo
Remote Worker Indonesia
3 min readOct 23, 2021

Every journey start with several simple steps: including your journey toward mastering SwiftUI development. These small early steps maybe somewhat boring. Or tiresome. But you must endure it. You may start with heavy steps at first, but just give yourself sometimes: push it and you’ll gradually love and passionate about it.

You may want to just start to use those sleek macOS/iOS UI components. But not yet grasshoper! Be patient. Before doing that, first you must have a fundamental knowledge about Swift syntax itself. Let’s do that here!

Fundamental of Swift Syntax

Apple is totally serious about Swift. Not just developing a new programming language, they also create a fantastic Playground to let you start learning Swift syntax in a fun and interactive environment. So, for this part of the article, go ahead and download Swift Playground: there are iPad and Mac versions. Pick any version. We are going to use it!

As a long time developer (I began coding in mid 90s), Swift syntax strike me as the combination of Python and Scala. Like in Python, there is no semicolon in Swift(yeaaah, suck that Java!). But unlike Scala, there is no curly braces in Swift (yeaaah, suck that again Java!). But unlike Python, Swift is statically typed language: like Scala. Meaning, you can’t change variable type once it’s initialized.

After years of Python coding, got to say, this kind of feature is awkward for me. In Python I can simply type any variable name and assign it to anything that I like: I never bother to write it’s type. I mean, when I type, icounter, .. it’s an integer, right? Although Python will allow you to assign a string to icounter, it’s seldom to never for programmer to assign different values to a variable intentionally: which actually means if you DID do that, well, your program will likely failed in runtime.

Now, enough with the ramblings! Let’s fireup Swift Playground and start a blank playground:

Enter our awesome Hello World program, press CMD+R and see the result in the right side.

If you don’t see the result view, look at the bottom right and click that red circle .. sheet icon. Nice eh?

With this new knowledge of Swift, in the next chapter you can directly start working with Swift syntaxes!

Thank you for reading!

--

--