0

I usually use a segue to pass some data between 2 ViewControllers. But now I have a 2D array (About 40Meg of data and in the future it may go to over 100Meg. It's a .json file). I read a few articles that tell all the different ways. But most ways (if not all) will make a copy of that data, and that takes time (in the launch screen it's acceptable but not when switching of ViewControllers). What method would you recommend? Putting my huge array as a global works fine, but it is frowned by many.

claudej
  • 3
  • 4
  • 2
    Use a wrapper class. Make your array be the property of a class and pass that object instead. Since objects are passed by reference, it will be fast. – vacawama Mar 17 '19 at 11:41
  • Or maybe reconsider if you really need to pass so much data between your view controllers. – Joakim Danielson Mar 17 '19 at 15:05

1 Answers1

0
class ArrayWapper {
    var array: [[Int]] = [[]] // Set your array .
}

And send an instance from that class to the second UIViewController as, @vacawama mentioned since its class it will pass the reference rather than a value copy of that array.

So in the second UIViewController you would have a variable of ArrayWapper class type, instead of simply [[Int]] array.

Mohmmad S
  • 5,001
  • 4
  • 18
  • 50