我想把结构体存储在数组中,在一个for循环中访问和改变结构体的值。
- struct testing {
- var value:Int
- }
- var test1 = testing(value: 6 )
- test1.value = 2
- // this works with no issue
- var test2 = testing(value: 12 )
- var testings = [ test1,test2 ]
- for test in testings{
- test.value = 3
- // here I get the error:"Can not assign to 'value' in 'test'"
- }
如果我把结构改成类工作。任何人都可以告诉我如何可以改变结构的值。