如何解决是否可以在Swift中通过@propertyWrapper创建带有引用副本的数组?像这样:
是否可以在Swift中使用@propertyWrapper创建带有引用副本的数组?像这样:
@propertyWrapper ... referenceArray ... {
...
subscript (index: Int) -> T {
get { return ... [index] }
set(newValue) { ... [index] = newValue }
...
}
struct Sample {
@referenceArray var tab1 = [2,3,5,7] // as class
@referenceArray var tab2: Array<Int>
func test() {
tab2 = tab1
if tab1 === tab2 { print("It's the same object") }
if tab1[2] == tab2[2] { print("It's the same element") }
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。