Swift uses error handling with do, try, and catch blocks.
do
try
catch
In Swift, you can write logs to the console with print statements or the more flexible os.log API, which hooks into the Unified Logging System on Apple platforms.
os.log
Imagine a task: calculate the average of an array. Without functions, you’d stick it all in main. With functions, you’d do this.
Let’s start with a basic Swift example where we have some repetitive code.