Hello World in Swift

Sure! Here's a simple "Hello, World!" program written in Swift:

swiftCopy code// hello_world.swift

// Print "Hello, World!" to the console
print("Hello, World!")

To run this Swift program, you can follow these steps:

  1. Open a text editor or an Integrated Development Environment (IDE) that supports Swift, such as Xcode for macOS.

  2. Create a new Swift file with the .swift file extension, and name it hello_world.swift (or any other preferred name).

  3. Enter the above Swift code into the hello_world.swift file.

  4. Save the file.

  5. Open a terminal and navigate to the directory where the hello_world.swift file is saved.

  6. Compile and run the Swift program by typing the following command in the terminal:

bashCopy codeswiftc hello_world.swift -o hello_world
./hello_world

The swiftc command compiles the Swift source code into an executable binary file named hello_world, and the ./hello_world command runs the compiled program, which will print "Hello, World!" to the console.

Note: If you are using Xcode or an IDE with Swift support, you can also run Swift programs directly within the IDE's built-in compiler and debugger.