Ad space (banner)
๐ŸฆSwift Lessons
Lesson 2 / 68

Your First Output (print)

In this lesson you will learn the basic way to print output in Swift with the print function, and get a feel for what kind of language Swift is. This is for anyone searching for "Swift print how to use".

print() displays text on the screen. Swift is Apple's official language for building iPhone and iPad apps. Announced by Apple in 2014, it is a modern language focused on safety and speed, and has replaced Objective-C as the standard for iOS and macOS development.

The sample code prints a string with the single line print("Hello, Swift!"). Not needing any fixed scaffolding such as a main method - you can simply run it - is another part of Swift's simplicity.

A common stumbling block for beginners is the difference between a Playground and real app development. Xcode's Playground feature lets you watch code behave immediately without building an app, whereas a real iPhone app needs a UI to display anything.

In real-world development, printing to the screen is the first step in checking behaviour and debugging. Swift has also been open-sourced and is starting to appear in server-side development.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Swift directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)