// MainApp.swift
import SwiftUI
@main
struct MainApp: App {
init() {
// The init() function runs when the app starts, so these two functions are executed before the UI is created
buildScan()
createData()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
// MARK: - Global vars
var gameArray: [String] = []
var cards: [Card] = [] // An array of your Card class
// MARK: - Startup functions
func buildScan() {
let emptyData = "1,,00.000000,00.000000,,,,,,,,2,,00.000000,00.000000,,,,,,,,3,,00.000000,00.000000,,,,,,,,4,,00.000000,00.000000,,,,,,,,5,,00.000000,00.000000,,,,,,,,6,,00.000000,00.000000,,,,,,"
gameArray = emptyData.components(separatedBy: ",")
}
func createData() {
// Two instances of the Card class are created here and added to the `cards` array. Note the name and city values; they're just example data.
cards.append(Card.init(coord: Coordinate(latitude: gameArray[2], longitude: gameArray[3]), name: "Card1", city: "London"))
cards.append(Card.init(coord: Coordinate(latitude: gameArray[2], longitude: gameArray[3]), name: "Card2", city: "San Francisco"))
}