freeCodeCamp/guide/english/swift/index.md

2.8 KiB

title
Swift

Swift Logo

What is Swift?

Swift is an open source, general-purpose programming language developed by Apple Inc. They describe it as:

Swift is a powerful and intuitive programming language for macOS, iOS, watchOS and tvOS. Writing Swift code is interactive and fun, the syntax is concise yet expressive, and Swift includes modern features developers love. Swift code is safe by design, yet also produces software that runs lightning-fast.1

Want to try out Swift right now? Repl.it offers an online Read-Eval-Print loop for Swift. You won't have access to UIKit or other APIs that are commonly used, but give it a shot!

Basics

To declare a variable in Swift, simply use var followed by the name of your variable.

var x = 6
var name = "Bob"
var boole = true

x = 3

Constants are similar to variables, but they cannot change in value after creation.

let x = 6
let name = "Bob"
let boole = true

To print anything to the standard output, simply use print() and place your output in the parentheses.

let x = "World"

print("Hello ")
print(x)

Version

The latest version is Swift 4.2, released Sept. 17, 2018. Swift is constantly evolving, and you can expect more changes in the future. It is recommended you use the latest version of Swift when starting a new project.

Documentation

Swift is heavily documented. Keep in mind that coding Swift involves not just using the language, but also many APIs. The best way to learn Swift is to make a project or application, no matter how small!

Want to learn more?

  • RayWenderlich.com : Has many great tutorials for Swift and iOS development.
  • Hacking with Swift : A complete Swift tutorial, taking you from a beginner to advanced using hands-on projects.

Sources

  1. "Swift 4 - The powerful programming language that is also easy to learn." Apple, developer.apple.com/swift, Accessed 31 Oct. 2017.