News for hackers. Stuff that matters.
Re:Should I use a Swift struct or a class? by RussianCow on Saturday July 04, 2015 @03:01PM (#9831230)

  let a = MyStruct(x: 1, y: 2)
  let b = a // Creates a copy of `a`
  b.x = 3 // Won't compile because you used "let", so its properties are immutable
  var c = a
  c.x = 3
  println(a.x) // Prints "1"; the original instance doesn't get changed

  let d = MyClass(x: 1, y: 2)
  let e = d // Refers to the same object as `d`
  e.x = 3 // Allowed, even though you used "let"
  println(d.x) // Prints "3"
That's a basic illustration of the difference between value types and reference types, but there are other differences between structs and classes as well (for instance, structs don't support inheritance or deinitializers).
Re:Should I use a Swift struct or a class? by holyjaw on Sunday July 05, 2015 @01:52AM (#9832621)
Nice example, thanks!