33 lines
539 B
Swift
33 lines
539 B
Swift
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])
|