属性、方法以及继承
This commit is contained in:
32
12 下标.playground/Contents.swift
Normal file
32
12 下标.playground/Contents.swift
Normal 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])
|
Reference in New Issue
Block a user