Last active
August 29, 2015 14:17
-
-
Save cSquirrel/0ad63991ce3997ea4977 to your computer and use it in GitHub Desktop.
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
class MyClass : NSObject { | |
var anArray:Array<String>? | |
func printDebug() -> String { | |
if (anArray != nil) { | |
return "Array has \(anArray!.count) element(s)" | |
} else { | |
return "No array" | |
} | |
} | |
func setArray(inout otherArray:Array<String>) { | |
// copy happens here | |
self.anArray = otherArray | |
} | |
} | |
let mc = MyClass() | |
mc.printDebug() | |
var items = Array<String>() | |
items.append("Item 1") | |
var otherItems = items | |
mc.anArray = items | |
mc.printDebug() // "Array has 1 element(s)" | |
items.append("Item 2") // ["Item 1", "Item 2"] | |
// since mc's array is a copy it's out of sync | |
mc.printDebug() // "Array has 1 element(s)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment