Bootstrap

swift中对象和结构体的使用

  • 对象 
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", age: 18)
print("姓名: \(stu.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("姓名: \(person.name)")//姓名: xiao

 

结构体不需要考虑引用计数,接头体是值赋值,就是a赋值给b,如果改变b,则a不变,举例

let person = Person(name: "xiao", age: 18)
print("姓名: \(person.name)")//姓名: xiao
var per1 = person;
per1.name = "da"

print("姓名: \(person.name)")//姓名: xiao

 

转载于:https://www.cnblogs.com/hualuoshuijia/p/11636187.html

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;