属性、方法以及继承

This commit is contained in:
2022-01-10 16:40:57 +08:00
parent 8de826239b
commit ad97b181bd
21 changed files with 501 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import UIKit
import CoreGraphics
struct Circle {
@@ -100,3 +101,70 @@ struct CircleA {
var circleA = CircleA()
circleA.radius = 10.5
print(circleA.radius)
struct Shape {
var width: Int
var side: Int {
willSet {
print("willSetSide", newValue)
}
didSet {
print("didSetSide", oldValue, side)
}
}
var girth: Int {
set {
width = newValue / side
print("setGirth", newValue)
}
get {
print("getGirth")
return width * side
}
}
func show() {
print("width=\(width), side=\(side), girth=\(girth)")
}
}
func test(_ num: inout Int) {
num = 20
}
var s = Shape(width: 10, side: 4)
test(&s.width)
s.show()
print("----------")
test(&s.side)
s.show()
print("----------")
test(&s.girth)
s.show()
struct CarA {
static var count: Int = 0
init() {
CarA.count += 1
}
}
let c1 = CarA()
let c2 = CarA()
let c3 = CarA()
print(CarA.count)
//
public class FileManager {
//
public static let shared = FileManager()
//
private init() {}
//
func run() {
}
}
FileManager.shared.run()