Created
September 1, 2016 19:26
-
-
Save mbuff24/1f02c13b7cba9bcb5a70b51b94d9b9e0 to your computer and use it in GitHub Desktop.
Copying a swift struct with a reference type property
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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