mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
35 lines
502 B
Swift
35 lines
502 B
Swift
// RUN: %target-run-simple-swift
|
|
|
|
// REQUIRES: executable_test
|
|
|
|
@propertyWrapper
|
|
struct Foo {
|
|
private var _storage: [Int] = []
|
|
|
|
init(wrappedValue value: [Int]) {
|
|
self._storage = value
|
|
}
|
|
|
|
var wrappedValue: [Int] {
|
|
get { _storage }
|
|
set { _storage = newValue }
|
|
}
|
|
}
|
|
|
|
class Bar {
|
|
@Foo var someArray = [1, 2, 3] {
|
|
willSet {
|
|
print(newValue)
|
|
}
|
|
|
|
didSet {
|
|
print(oldValue)
|
|
}
|
|
}
|
|
}
|
|
|
|
let bar = Bar()
|
|
// CHECK: [4, 2, 3]
|
|
// CHECK: [1, 2, 3]
|
|
bar.someArray[0] = 4
|