0

I am trying to pass an Array Object between 2 view controllers. But I want the Array to be passed as a Reference and not copied. I know if I was using a function locally, I can use "inout" and "&" based on the examples I found.

But I what I want to do is slightly different. I want to assign the Array in VC1 directly to the Array object in VC2 as a reference. Here is my code:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "vc2" {

        let vc2 = segue.destinationViewController as! ProfileVC

        vc2.data = &self.data       //I know this line doesn't work, how would I go about it?

    }

}

1 Answer 1

1

Swift array are struct, so they will get copied.

The simplest way would be to use an object instead of a struct. So I would use a NSMutableArray instead.

With that you will have all the power of mutability at your finger tips ;-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.