- Object
class Student{
var name: String = "";
var age: Int = 0;
init(name: String ,age:Int) {
self.name = name
self.age = age
}
}
let stu = Student(name: "xiao< span style="color: #800000;">", age: 18)
print("Name: \(stu.name)")//Name : Xia
- Structure
struct Person{ var name: String = ""; var age: Int = 0; init(name: String ,age:Int) { self.name = name self.age = age } } let person = Person(name: "xiao", age: 18) print("Name: \(person.name)")//Name: xiao
The structure body does not need to consider the reference count. The joint body is a value assignment, that is, a is assigned to b. If you change b, then a remains unchanged, for example
p>
let person = Person(name: "xiao", age: 18) print("Name: \(person.name)")//Name: xiao var per1 = person; per1.name = "da" print("Name: \(person.name)")//Name: xiao
class Student{
var name: String = "";
var age: Int = 0;
init(name: String ,age:Int) {
self.name = name
self.age = age
}
}
let stu = Student(name: "xiao< span style="color: #800000;">", age: 18)
print("Name: \(stu.name)")//Name : Xia
struct Person{ var name: String = ""; var age: Int = 0; init(name: String ,age:Int) { self.name = name self.age = age } } let person = Person(name: "xiao", age: 18) print("Name: \(person.name)")//Name: xiao
let person = Person(name: "xiao", age: 18) print("Name: \(person.name)")//Name: xiao var per1 = person; per1.name = "da" print("Name: \(person.name)")//Name: xiao