2021-09-06 07:04:43 +02:00
|
|
|
# Untyped inline property
|
|
|
|
var prop1:
|
|
|
|
get:
|
|
|
|
return prop1
|
|
|
|
set(value):
|
|
|
|
prop1 = value
|
|
|
|
|
|
|
|
# Typed inline property
|
2023-03-03 15:42:32 +01:00
|
|
|
var prop2: int:
|
2021-09-06 07:04:43 +02:00
|
|
|
get:
|
|
|
|
return prop2
|
|
|
|
set(value):
|
|
|
|
prop2 = value
|
|
|
|
|
|
|
|
# Typed inline property with default value
|
2023-03-03 15:42:32 +01:00
|
|
|
var prop3: int = 1:
|
2021-09-06 07:04:43 +02:00
|
|
|
get:
|
|
|
|
return prop3
|
|
|
|
set(value):
|
|
|
|
prop3 = value
|
|
|
|
|
|
|
|
# Typed inline property with backing variable
|
2023-03-03 15:42:32 +01:00
|
|
|
var _prop4: int = 2
|
2021-09-06 07:04:43 +02:00
|
|
|
var prop4: int:
|
|
|
|
get:
|
|
|
|
return _prop4
|
|
|
|
set(value):
|
|
|
|
_prop4 = value
|
|
|
|
|
|
|
|
func test():
|
|
|
|
print(prop1)
|
|
|
|
print(prop2)
|
|
|
|
print(prop3)
|
|
|
|
print(prop4)
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
prop1 = 1
|
|
|
|
prop2 = 2
|
|
|
|
prop3 = 3
|
|
|
|
prop4 = 4
|
|
|
|
|
|
|
|
print(prop1)
|
|
|
|
print(prop2)
|
|
|
|
print(prop3)
|
|
|
|
print(prop4)
|