Because you are (trying) to edit a copy. To edit the value in the array itself use:
array[index].number += 1 Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server for websites build in Swift > On 26 Apr 2017, at 16:15, J.E. Schotsman via swift-users > <swift-users@swift.org> wrote: > > Simple question: why can’t I edit a variable array with a functional method? > > For example: > > struct TestStruct > { > var number = 0 > } > > var array = [TestStruct](repeatElement(TestStruct(), count: 2)) > array.forEach { $0.number += 1 } > > Jan E. > _______________________________________________ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users _______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users