I use an array of objects. Then I add some of them to another array. But they are copied. So when I change their content the original value remains unchanged.
var primary = [fileObj]()
for image in images {
if image.oldID != 0 && image.priority != noPriority {
primary.append(image)
}
}
How can I add a reference in the array, so I'm able to change the content directly in the object?
E.g.:
primary[2].priority = -1
From the given code the only reason this should happen is if
fileObj
is a struct.struct
instances are copied by value whileclass
instances are passed by reference so changefileObj
to be a class rather than a struct.