You can use Swift (very unconvincing) UnsafeMutablePointer .
Since (from your post) references to behavior in arrays cannot be really reliable, instead, save the UnsafeMutablePointer companion for the internal array of class foo , as well as any "external" arrays that you want attached to foo , in the sense that they are both are pointers to the same address in memory.
class Foo { var foo : [Int] var pInner: UnsafeMutablePointer<Int> init(foo: [Int]) { pInner = UnsafeMutablePointer(foo) self.foo = Array(UnsafeBufferPointer(start: pInner, count: foo.count)) } func modify(inout pOuter: UnsafeMutablePointer<Int>) { foo.append(5)
Pointers can be dangerous, though (hence the name of the fit type), and, again, very careless. Anyway...
bar.pInner = nil pOuter = nil
Now, what happens when either a or foo goes out of scope, will it violate a variable that is not out of scope, or will Swift contain some smart reference counting that implements a memory address is still in use? I have not researched this, but I am not shy about doing it.
source share