Swift cheatsheet for JavaScript developers

Written by Michael Lee on June 7, 2018

Message output

JavaScript Swift
console.log("Hello world!") print("Hello world!")

Variables

JavaScript Swift
const pi = 3.14 let pi = 3.14
let name = "Michael" var name = "Michael"

String interpolation

JavaScript Swift
`Michael is ${age} years old` "Michael is \(age) years old"

Javascript

let intro = `
This is a story about a boy.
His name was ${name}
`

Swift

var intro = """
This is a story about a girl.
Her name was \(name)
"""

Array

JavaScript Swift
let names = ["John", "Jill", "Mary"] var names = ["John", "Jill", "Mary"]

Object/Dictionary

JavaScript

let car = {
  "make": "Audi",
  "model": "A3",
  "color": "White"
}

Swift

var car = [
  "make": "Audi",
  "model": "A3",
  "color": "White"
]

Changelog

2018-06-08
Initial notes
Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design, side projects and working remotely. Sign up and I'll send you my articles straight to your email.

:wave: Hey hey, I'm Michael Lee! I really appreciate you taking the time to read this article.

Be sure to check out my other articles.