Swift Get Started

Install the Swift toolchain and run your first “Hello, Swift!” program from the terminal or Xcode.


Install Swift

Swift can be installed on macOS, Windows, and Linux.

  • macOS (Xcode): Install Xcode from the App Store. Xcode includes the Swift compiler, SDKs, and tools.
  • macOS (Command line): Install the Swift toolchain, then run swift --version.
  • Windows/Linux: Install the platform toolchain from swift.org/install and ensure swift is on your PATH.

Check install: Run swift --version in a terminal.

You should see the Swift version and target.


Hello World

Swift can be run from the terminal or Xcode.

Syntax: print("Hello, Swift!"); run with swift main.swift (or your toolchain’s run command).

Example

main.swift

print("Hello, Swift!")

Example explained

  • main.swift: A Swift file; the top-level print executes when run.
  • print: Writes text to standard output. Strings use double quotes.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *