If you want to run this program in your computer, make sure that Swift and Xcode is properly installed. For that, check How to run Swift on your computer?
Let's explore how to create Swift "Hello, World!" program.
// Hello, World! Program import Swift print("Hello, World!")
Copy the exact code onto the Xcode Playground.
When you run the program, the output will be:
// Hello, World! Program
//is a comment. They are completely ignored by the compiler. Comments are intended for person reading the code to better understand the intent and functionality of the program. If you want to learn more about comments visit Swift Comments.
importkeyword allows you to access all the symbols defined inside a framework.For now, just remember this line is required to use
print("Hello, World!")in our program. You’ll learn more about it in the later tutorials.
swiftand press enter (return). This will give you a welcome message as Welcome to Apple Swift version x.x.x.
When you hit the enter (or return) key, the output will be :
import Swiftfrom your program because it’s automatically included in the playground for you.
Don’t worry if you don’t understand some concepts in this tutorial for now, we’ll discuss them in detail in our later tutorials.