Reputation: 1581
I have a struct which looks like this
struct myStruct {
var array1: [String]
var additionalInfo: String?
var array2: [String]
}
var appendMe = [myStruct(array1: ["Value1"], additionalInfo: nil, array2: ["Value1","Value2"])]
in MainViewController i append it with additional values, but when i try to access them from the AppDelegate, for instance like this
appendMe[array1.count-1].array2[0]
I always keep getting the original values set in the struct before the update. Just like Xcode creates a separate instance of the struct for MainViewController and AppDelegate.
How to i fix this issue?
Thank you!
Upvotes: 0
Views: 191
Reputation: 22701
Structs are passed by value in Swift, not by reference. Your main view controller is modifying a copy of the struct, not the one you think.
Upvotes: 2