属性、方法以及继承

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

@@ -0,0 +1,32 @@
import Cocoa
class Point {
var x = 0.0, y = 0.0
subscript(index: Int) -> Double {
set {
if index == 0 {
x = newValue
} else if index == 1 {
y = newValue
}
}
get {
if index == 0 {
return x
} else if index == 1 {
return y
}
return 0
}
}
}
var p = Point()
p[0] = 11.1
p[1] = 22.2
print(p.x)
print(p.y)
print(p[0])
print(p[1])