Skip to content

Instantly share code, notes, and snippets.

@mbuff24
Created September 1, 2016 19:26
Show Gist options
  • Save mbuff24/1f02c13b7cba9bcb5a70b51b94d9b9e0 to your computer and use it in GitHub Desktop.
Save mbuff24/1f02c13b7cba9bcb5a70b51b94d9b9e0 to your computer and use it in GitHub Desktop.
Copying a swift struct with a reference type property
//: Playground - noun: a place where people can play
import UIKit
class Person: CustomDebugStringConvertible {
let name: String
init(name: String) {
self.name = name
}
var debugDescription: String {
get {
return name
}
}
}
struct House {
var owner: Person
var address: String
}
let alice = Person(name: "Alice")
var house1 = House(owner: alice, address: "1")
house1.owner // Alice
var house2 = house1
house2.owner // Alice
house1.owner === house2.owner // true, same ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment