Picture of Michael Lee
:wave: Hey hey, I'm Michael Lee and this is my site about being a developer, being a dad and making side projects.

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
Thanks for taking the time to read this article. I'd love to stay in touch and share more tips on programming and design and side projects. Sign up and I'll send you my articles straight to your email.