var dept = Department() ① dept.no = 10 dept.name = "Sales" ② var emp = Employee() ③ emp.no = 1000 emp.name = "Martin" emp.job = "Salesman" emp.salary = 1250 emp.dept = dept ④ func updateDept (dept : Department) { ⑤ dept.name = "Research" ⑥ } println("Department更新前:\(dept.name)") ⑦ updateDept(dept) ⑧ println("Department更新后:\(dept.name)") ⑨ func updateEmp (emp : Employee) { ⑩ emp.job = "Clerk" ? } println("Employee更新前:\(emp.job)") ? updateEmp(emp) ? println("Employee更新后:\(emp.job)") ?
var emp1 = Employee() ① emp1.no = 1000 emp1.name = "Martin" emp1.job = "Salesman" emp1.salary = 1250 var emp2 = Employee() ② emp2.no = 1000 emp2.name = "Martin" emp2.job = "Salesman" emp2.salary = 1250 if emp1 === emp2 ③ { println("emp1 === emp2") } if emp1 === emp1 ④ { println("emp1 === emp1") } var dept1 = Department() ⑤ dept1.no = 10 dept1.name = "Sales" var dept2 = Department() ⑥ dept2.no = 10 dept2.name = "Sales" if dept1 == dept2 //编译失败 ⑦ { println("dept1 === dept2") }
我们发现会有编译错误。===不能比较值类型,而Department结构体是值类型,因此不能使用===比较。
欢迎关注智捷iOS课堂微信公共平台
原文地址:http://blog.csdn.net/tonny_guan/article/details/38946779