比我說得好比我說得好比我說得好,重要的說三遍
http://blog.csdn.net/hello_hwc/article/details/50102329
下面是自己的理解
1、類賦值
class SomeClass {
var name : String?
var age = 25
}
var oneClass = SomeClass()
oneClass.name = "牛大膽"
print(oneClass.age)
print(oneClass.name!)
var twoClass = oneClass
twoClass.name = "狗指導(dǎo)"
print("\(twoClass.name!)+\(oneClass.name!)")
//對象比較用===
if twoClass === oneClass {
print("兩個(gè)相等")
}
可以看出類的賦值var twoClass = oneClass
是淺copy,拷貝了指針辞做。
2搬素、結(jié)構(gòu)體賦值
struct SomeStruct {
var anyClass = SomeClass()
var company : String?
var salary = 10000
}
var oneStruct = SomeStruct()
oneStruct.company = "百得康"
var twoStruct = oneStruct
twoStruct.company = "雙乾"
print("\(oneStruct.company!) -- \(twoStruct.company!)")
可以看出結(jié)構(gòu)體的賦值var twoStruct = oneStruct
是深copy,拷貝了value诡右。
3碘赖、基本類型String和NSMutableArray舉例
var companyName : String?
companyName = "雙乾"
var companyName2 = companyName
companyName2 = "百得康"
print("\(companyName!)--\(companyName2!)")
var nameArray : NSMutableArray?
nameArray = ["雙乾","百得康"]
var nameArray2 = nameArray
nameArray2!.add("聯(lián)康")
print("\(nameArray!)--\(nameArray2!)")
print("%p--%p",nameArray!,nameArray2!)