Swift – Hello World Program
Swift is a Programming Language used for developing iOS-based platforms like macOS, apple mobiles, apple iOS Watches, iOS TVs, iOS Keywords, iOS Mouse, and other iOS Software-based Peripherals. This language is almost 80% similar to C and Python languages. Once who is familiar with C and Python languages can easily learn swift language. Swift programming language is easy to use and also a powerful programming language. Swift programming language is highly known for best security programming language in the world. Swift concepts are mostly derived from C and Objective-C Concepts. It is simple and easy to use and provides high security. The syntax of Swift is also very easy to learn. In this article, we will create a simple hello world program in Swift language.
Before getting started, see what are the advantages of using Swift programming
Advantages:
- Easy to learn and understand. Not very complex program to code it is easy to learn on the go.
- Powerful programming language for building better applications.
- Help in designing application UI with library functions.
- Long term development support and great community.
- Trust and Security
Hello World Program in Swift
We can create a swift program file with .swift extension. To run a swift program we required XCode in our system. If you don’t have one you can use some online compiler which you can find a lot of them with the same XCode features. To create and run a hello world program follow the following steps:
Step 1: Open XCode in your system.
Step 2: Create a new XCode project.
Step 3: Select the command-line tool and then click on the Next button.
Step 4: Give a name to your project like here we give “helloworld” and then click on next button.
Step 5: Select the project location and then click on the create button. Now the project is created.
Step 6: Now open main.swift file in the project navigator.
Step 7: Enter the following code in the main.swift file.
Swift
import Foundation print ( "Hello, World!" ) |
Explanation: In the first line we use the import keyword to import namespaces that contain a set of predefined symbols or functions. So using the namespace we can easily access them. And in the second line we are using a print(“”) function for printing Hello World! as program output.
Step 8: Now press the Run button to run the main.swift file and you will get the following output:
Contact Us