Skip to content

Instantly share code, notes, and snippets.

@hanawat
Created January 16, 2016 17:59
Show Gist options
  • Save hanawat/2edc4aa4045c61c562ba to your computer and use it in GitHub Desktop.
Save hanawat/2edc4aa4045c61c562ba to your computer and use it in GitHub Desktop.
Inheritance to Class (NSObject), it'll be the reference type.
import Foundation
let apple: NSMutableArray = ["🍎", "🍎"]
var orange = apple
orange.replaceObjectsInRange(NSMakeRange(0, apple.count), withObjectsFromArray: ["🍊", "🍊"])
print("apple=\(apple)", "orange=\(orange)") // a=[🍊, 🍊] b=[🍊, 🍊]
import Foundation
let apple: NSMutableString = "🍎"
let orange: NSMutableString = apple
orange.setString("🍊")
print("apple=\(apple)", "orange=\(orange)") // a=🍊 b=🍊
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment