i = 3
@name = "John Doe"
self.cat = Cat.new(:tabby)
puts self.cat
var i = 3; // or let this.name = "John Doe"; this.cat = new Cat('tabby'); console.log(this.cat);
let i = 3
self.name = "John Doe"
self.cat = Cat("tabby")
print(self.cat)
a = 1 # assign an integer b = "a string" # assign a string c = [2, 4, 6, 8] # assign an array d = {abc: "some", xyz: "values"} # dictionary / hash
let a = 1; let b = "a string"; let c = [2, 4, 6, 8]; let d = {"abc": "some", "xyz": "values"};
note: let is the new, improved alternative to var in ES6, because reasons.
let a = 1 let b = "a string" let c = [2, 4, 6, 8] let d = ["abc": "some", "xyz": "values"]
note: let here is NOT the same thing as let in ES6. let in Swift creates a constant, aka a "variable" that is actually immutable.
a = 12345
b = "a string with #{a} in it"
puts b.include? "123" # true
let a = 12345;
let b = `a string with ${a} in it`;
console.log(b.indexOf("123") != -1); // true
console.log(b.includes("123")); // ES6: true
note: that backticks syntax looks pretty eewww, but it's definitely useful
let a = 12345 let b = "a string with \(a) in it"
print(b.contains("123")) // true
note: that backticks syntax looks pretty eewww, but it's definitely useful
range1 = 1..5 # 1, 2, 3, 4, 5
range2 = 1...5 # 1, 2, 3, 4
(just kidding, Javascript doesn't have ranges)
let range1 = 1..<5 # 1, 2, 3, 4
let range2 = 1...5 # 1, 2, 3, 4, 5
note: OMG, ... is the opposite of Ruby!
myArray = [1,7,8] growingArray = [] myArray.each do |i| growingArray << i + 23 if i > 2 end
var myArray = [1,7,8]; var growingArray = []; myArray.forEach(function(i) { if (i > 2) { growingArray.push(i + 23) } });
let myArray = [1,7,8] var growingArray = [Int]() myArray.forEach {(i: Int) in if i > 2 { growingArray.append(i + 23) } }
class Frog < PondAnimal def initialize super self.sound = "ribbit" end end
class Frog extends PondAnimal { constructor() { super(); this.sound = "ribbit"; } }
note: the new OOP stuff in ES6 is really, really nice
class Frog: PondAnimal { override init() { super.init() self.sound = "ribbit" } }
note: seeing a pattern here? Swift syntax is surprisingly easy on the eyes (most of the time)
code examples at
There are {{ articles.count }} articles. {% for article in articles %} - {{ article.title }} by {{ article.author }}. {% endfor %}
note: yep, this looks just like Liquid
I think Apple's really gone all out in making Swift a true cross-platform, performant, general-purpose programming language with a touch of pizazz.
Well done.