类 结构体
//结构体
struct teacher {
var name:String = ""
var age:Int = 19
}
class Student{
var name:String = ""
var age:Int = 18
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let classItem = Student() //创建实例
classItem.name = "花花菇凉"
print(classItem.name)
}
}
属性
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var allName = newClass()
allName.name
let stepCount = StepCount()
stepCount.examplePro = 200
}
}
class Student {
var name:String?
var age:Int = 10
}
class newClass{
// lazy var name = "小明" //懒加载属性
var lastName = "小小"
var firstName = "苏"
var name:String{
get {
return firstName + lastName
}
}
}
class StepCount {
var examplePro:Int = 10 {
willSet (newTotal){
//在属性更改之前做的操作
print("新值是\(newTotal)")
}
didSet{
//在属性更改之后的操作
print("新值-旧值\(examplePro - oldValue)")
}
}
}