Installing Swift
Sprout's logic can be tried in minutes, but only once Swift is on your machine. The good news is that there is one obvious route per computer. The catch is that the Swift language and the SwiftUI screens do not have quite the same requirements.
The rule
Language anywhere; SwiftUI screens need a Mac with Xcode.
The Swift language installs almost everywhere:
- Mac: install Xcode from the Mac App Store. It brings the Swift compiler, the iPhone simulator, and live SwiftUI previews.
- Linux and Windows: download the Swift toolchain from swift.org using the installer for your system.
- iPad or Mac, no setup: the Swift Playgrounds app lets you write and run Swift straight away.
Check that it worked from a terminal:
swift --versionThen run a single file of Swift directly:
swift sprout.swiftFor anything bigger than one file, make a package and let Swift build and run it:
swift package init --type executable
swift runSwiftUI is different. It is one of Apple's frameworks, so building and previewing SwiftUI screens for iPhone needs a Mac with Xcode. On Linux you can write and run plain Swift, but not an iPhone app.
The shortcut
Ask one question: am I writing logic, or drawing screens? Logic (Sprout's streak maths, its rules for a missed day) runs wherever Swift is installed. Screens need Xcode on a Mac.
Decide what you are building today
Today you only want to test streak rules. That is plain Swift logic.
The common mistake is expecting a Windows or Linux install to preview an iPhone screen. The compiler is the same language; the Apple frameworks are not there.
Drills
Answer fast — trust the rule.
Which command checks that the Swift compiler is installed?
You are on a Linux laptop. What can you do?
What does installing Xcode on a Mac give you?
Your Sprout logic has grown to several files. What is the usual command-line route?
Remember
- Language anywhere; SwiftUI screens need a Mac with Xcode.
- Ask: am I writing logic, or drawing screens?
swift --versionchecks;swift file.swiftruns one file;swift runruns a package.
