Swift cheatsheet for JavaScript developers

Written 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

Stay in touch

Thanks for reading this article. I'd love to stay in touch and share articles like this one in your inbox. Sign up for my newsletter.