Files
freeCodeCamp/guide/english/swift/index.md
Jason Antwi-Appah 47e5e8d47a Feat: Added info on Xcode to introduction (#36566)
* Feat: Added info on Xcode to introduction

I also added an example of string interpolation to the basics section, and updated the current version of Swift.

* Added a missing parenthesis
2019-08-09 21:22:27 -07:00

3.8 KiB

title
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! If you have access to a macOS device, you can also install Xcode, Apple's free IDE for tvOS, watchOS, iOS, and macOS. It can be installed from the Mac App Store.

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)
print("Hello \(x)")

Version

The latest version is Swift 5.0, released March 25, 2019. 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?

Sources

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