[Solved] Creating a global multi dimensional array Swift 4 [closed]


Keep products as structures:

struct Product {
  let id: Int
  let quantity: Int
  let price: Double
}

then define array:

internal static var productArray = [Product]()

and add your products.

let product = Product(id: 1, quantity: 99, price: 1.99)
productArray.append(product)

internal static prefix lets you to reach the array throughout the app. However, I don’t think you want to use this pattern in your app.

1

solved Creating a global multi dimensional array Swift 4 [closed]