Skip to content

Instantly share code, notes, and snippets.

@fcanas
Created January 11, 2018 18:31
Show Gist options
  • Save fcanas/477567126357d3afb1bace1096f4f64e to your computer and use it in GitHub Desktop.
Save fcanas/477567126357d3afb1bace1096f4f64e to your computer and use it in GitHub Desktop.
Copy Properties in Swift
import Foundation
class C {
@NSCopying var copiedName: NSString?
var noCopyName: NSString?
}
let f = NSMutableString(string: "First")
let obj = C()
obj.copiedName = f
obj.noCopyName = f
obj.copiedName // "First"
obj.noCopyName // "First"
f.append(" Last")
obj.copiedName // "First"
obj.noCopyName // "First Last"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment