是否可以在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 (将#修改为@)