ソースコード source code

下記アプリの主要なソースコードを公開しています。アプリ開発の参考になれば幸いです。

画像等が別途必要ですので下記情報のみでアプリが完成するものではありません。 アプリは少しずつ機能拡張していますのでストア公開されているアプリと内容が異なる場合があります。 コードはコピーして自由にお使いいただけます。ただし著作権は放棄しておりませんので全部の再掲載はご遠慮ください。部分的に再掲載したり、改変して再掲載するのは構いません。 自身のアプリ作成の参考として個人使用・商用問わず自由にお使いいただけます。 コード記述のお手本を示すものではありません。ミニアプリですので変数名などさほど気遣いしていない部分も有りますし間違いも有るかと思いますので参考程度にお考え下さい。 他の賢者の皆様が公開されているコードを参考にした箇所も含まれます。iOSアプリ開発の熟練者が書いたコードではありません。 エンジニア向け技術情報共有サービスではありませんので説明は省いています。ご了承ください。 GitHubなどへの公開は予定しておりません。

下記コードの最終ビルド日: 2021-04-19

BingoMachineApp.swift

//
//  BingoMachineApp.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/04/02.
//

import SwiftUI
import UIKit
import GoogleMobileAds

// AppDelegateクラスを定義する
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        // Mobile Ads SDKを初期化する
        GADMobileAds.sharedInstance().start(completionHandler: nil)
        
        return true
    }
}

@main
struct BingoMachineApp: App {
    // SwiftUI AppライフサイクルにAppDelegateクラスを注入する
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView().environmentObject(PublicManager())
        }
    }
}

CardView.swift

//
//  CardView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/30.
//

import SwiftUI

struct CardView: View {
    @EnvironmentObject var pub: PublicManager
    let cellHeaderHeight: CGFloat = 25.0
    let cellHeight: CGFloat = 70.0
    let cellWidthRatio: CGFloat = 5.5
    func sellWidth(screenWidth: CGFloat) -> CGFloat {
        return screenWidth / self.cellWidthRatio
    }
    func sellColor(open: Bool) -> Color {
        return open ? ConstValue.colorOpen : ConstValue.colorBg
    }
    func sellText(num1: Int, num2: Int) -> String {
        return String(self.pub.cardText[num1 * 5 + num2])
    }

    var body: some View {
        ZStack {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    ZStack {
                        Button(action:{
                            self.pub.isCard = false
                        }){
                            Text("card")
                                .frame(height: 50)
                                .frame(minWidth: 0, maxWidth: bodyView.size.width, alignment: .center)
                                .background(Color.green)
                                .foregroundColor(Color.white)
                        }
                        HStack {
                            Button(action:{
                                self.pub.isCard = false
                            }){
                                Image(systemName: "arrow.backward").foregroundColor(.white)
                                    .frame(minWidth: 0, maxWidth: bodyView.size.width / 8, alignment: .center)
                            }.frame(height: 50)
                            Spacer()
                        }
                    }.frame(height: 50)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            Spacer(minLength: 10)
                            HStack {
                                Spacer()
                                VStack {
                                    HStack(spacing: 0) {
                                        Text("B").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight: self.cellHeaderHeight)
                                            .border(Color.green, width: 1)
                                            .background(Color.green)
                                        Text("I").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight: self.cellHeaderHeight)
                                            .border(Color.green, width: 1)
                                            .background(Color.green)
                                        Text("N").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight: self.cellHeaderHeight)
                                            .border(Color.green, width: 1)
                                            .background(Color.green)
                                        Text("G").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight: self.cellHeaderHeight)
                                            .border(Color.green, width: 1)
                                            .background(Color.green)
                                        Text("O").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight: self.cellHeaderHeight)
                                            .border(Color.green, width: 1)
                                            .background(Color.green)
                                    }
                                    ForEach(0..<5) { num1 in
                                        HStack(spacing: 0) {
                                            ForEach(0..<5) { num2 in
                                                if num1 * 5 + num2 == 12 {
                                                    Text("F")
                                                        .font(.largeTitle)
                                                        .foregroundColor(Color.black)
                                                        .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                        .border(Color.green, width: 1)
                                                        .background(ConstValue.colorOpen)
                                                } else {
                                                    Button(action:{
                                                        self.pub.cardOpen[num1 * 5 + num2].toggle()
                                                        self.pub.saveCard()
                                                    }){
                                                        Text(self.sellText(num1: num1, num2: num2))
                                                            .font(.largeTitle)
                                                            .foregroundColor(Color.black)
                                                            .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                            .border(Color.green, width: 1)
                                                            .background(self.sellColor(open: self.pub.cardOpen[num1 * 5 + num2]))
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }.border(Color.green, width: 2).frame(maxHeight: .infinity)
                                Spacer()
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
            }
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
        .onAppear {
            self.pub.loadCard()
        }
    }
}

struct CardView_Previews: PreviewProvider {
    static var previews: some View {
        CardView()
            .environmentObject(PublicManager())
    }
}

ConstValue.swift

//
//  ConstValue.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/29.
//

import SwiftUI

class ConstValue: ObservableObject {
    
    //const
    static let ballCount: Int = 75
    static let colorBg: Color = Color.init(red:0.093,green:0.965,blue:0.477)
    static let colorOpen: Color = Color.init(red:1.0,green:1.0,blue:0.2)
    static let colorOpenLast: Color = Color.init(red:1.0,green:0.5,blue:0.2)
    
    //button color
    static let colorSpinMachine: Color = Color.init(red:0.238, green:0.77, blue:0.387)
    static let colorProgress: Color = Color.init(red:0.25, green:0.77, blue:0.285)
    static let colorHistory: Color = Color.init(red:0.387, green:0.77, blue:0.29)
    static let colorCard: Color = Color.init(red:0.543, green:0.77, blue:0.289)
    static let colorSetting: Color = Color.init(red:0.703, green:0.77, blue:0.293)
}

ContentView.swift

//
//  ContentView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/27.
//

import SwiftUI
import AVKit

struct ContentView: View {
    @EnvironmentObject var pub: PublicManager
    private let player1: AVPlayer = AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "bingo", ofType: "mp4")!))
    @State private var playerPlay: Bool = false
    private var ballImage: String = "ball"
    @State private var ballAlpha: Double = 0.0
    @State private var ballNumAlpha: Double = 0.0
    @State private var ballNum: String = ""
    @State private var ballEnd: Bool = false
    @State private var busyFlag: Bool = false
    @State private var destroyFlag: Bool = false

    private func ballNumSize(w: CGFloat) -> CGFloat {
        return self.ballEnd ? w / 16 : w / 3.5
    }

    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.spinMachine()
                        }){
                            Text("spinMachine")
                                .frame(width:bodyView.size.width / 4 * 3, height: 100, alignment: .center)
                                .background(ConstValue.colorSpinMachine)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: 100)
                        VStack(spacing: 0) {
                            NavigationLink(destination: SettingView(),isActive: self.$pub.isSetting) {
                                Button(action:{
                                    self.pub.isSetting = true
                                }){
                                    Text("setting")
                                        .frame(width:bodyView.size.width / 4, height: 40, alignment: .center)
                                        .background(ConstValue.colorSetting)
                                        .foregroundColor(Color.white)
                                }
                            }
                            Rectangle().fill(Color.white).frame(width: bodyView.size.width / 4,height: 1)
                            NavigationLink(destination: CardView(),isActive: self.$pub.isCard) {
                                Button(action:{
                                    self.pub.isCard = true
                                }){
                                    Text("card")
                                        .frame(width:bodyView.size.width / 4, height: 60, alignment: .center)
                                        .background(ConstValue.colorCard)
                                        .foregroundColor(Color.white)
                                }
                            }
                        }
                        .background(Color.green)
                    }
                    .frame(width:bodyView.size.width, height:100)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    HStack(spacing: 0) {
                        NavigationLink(destination: ProgressView(),isActive: self.$pub.isProgress) {
                            Button(action:{
                                self.pub.isProgress = true
                            }){
                                Text("progress")
                                    .frame(width:bodyView.size.width / 2, height: 50, alignment: .center)
                                    .background(ConstValue.colorProgress)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(Color.green)
                        Rectangle().fill(Color.white).frame(width: 1,height: 50)
                        NavigationLink(destination: HistoryView(),isActive: self.$pub.isHistory) {
                            Button(action:{
                                self.pub.isHistory = true
                            }){
                                Text("history")
                                    .frame(width:bodyView.size.width / 2, height: 50, alignment: .center)
                                    .background(ConstValue.colorHistory)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(Color.green)
                    }
                    .frame(width:bodyView.size.width, height: 50)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            ZStack(alignment: .top) {
                                VStack {
                                    PlayerView(player: self.player1)
                                }.frame(width:bodyView.size.width, height:bodyView.size.width)
                                Group {
                                    Image(self.ballImage)
                                        .resizable()
                                        .frame(width: bodyView.size.width / 2, height: bodyView.size.width / 2, alignment: .topLeading)
                                        .opacity(self.ballAlpha)
                                        .overlay(
                                            Text(self.ballNum)
                                                .foregroundColor(Color.black)
                                                .font(.system(size: self.ballNumSize(w: bodyView.size.width), weight: .black, design: .default))
                                                .opacity(self.ballNumAlpha),
                                            alignment: .center
                                        )
                                }.position(x: bodyView.size.width / 3.6 , y: bodyView.size.width / 3.6)
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .onAppear {
            self.pub.loadHistory()
            self.pub.ballHistoryDraw()
        }
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }

    private func spinMachine() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //終わりか否かを調べる
        if self.nextBall() == -1 { //end
            self.ballEnd = true
            self.ballNumAlpha = 1.0
            self.ballNum = NSLocalizedString("empty", comment: "empty")
            self.busyFlag = false
            return
        }
        //
        self.ballEnd = false
        self.ballAlpha = 0.0
        self.ballNumAlpha = 0.0
        self.player1.seek(to: CMTime(seconds: 0, preferredTimescale: 600))
        self.player1.play()
        self.spinMachineEndWait(num: 0)
    }

    private func spinMachineEndWait(num: Int) {
        withAnimation {
            if self.destroyFlag {
                return
            }
            if num > 130 {
                self.spinMachineEnd()
                self.busyFlag = false
                return
            }
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.05)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.spinMachineEndWait(num: num + 1)
                    }
                }
            }
        }
    }

    private func spinMachineEnd() {
        let nextBall: Int = self.nextBall()
        if nextBall == -1 { //念のため。開始前に調査しているので-1になることはない
            return
        }
        self.ballAlpha = 1.0
        self.ballNumAlpha = 1.0
        self.ballNum = "\(nextBall + 1)"
        if self.pub.history.contains(nextBall) == false {
            self.pub.history += [nextBall]
        }
        
        /*      //test
        self.pub.history += [1]
        self.pub.history += [2]
        self.pub.history += [3]
        self.pub.history += [4]
        self.pub.history += [5]
        self.pub.history += [6]
        self.pub.history += [7]
        self.pub.history += [8]
        self.pub.history += [9]
        self.pub.history += [10]
        self.pub.history += [11]
        self.pub.history += [12]
        self.pub.history += [13]
        self.pub.history += [14]
        self.pub.history += [15]
        self.pub.history += [16]
        self.pub.history += [17]
        self.pub.history += [18]
        self.pub.history += [19]
        self.pub.history += [20]
        self.pub.history += [21]
        self.pub.history += [22]
        self.pub.history += [23]
        self.pub.history += [24]
        self.pub.history += [25]
        self.pub.history += [26]
        self.pub.history += [27]
        self.pub.history += [28]
        self.pub.history += [29]
        self.pub.history += [30]
        self.pub.history += [31]
        self.pub.history += [32]
        self.pub.history += [33]
        self.pub.history += [34]
        self.pub.history += [35]
        self.pub.history += [36]
        self.pub.history += [37]
        self.pub.history += [38]
        self.pub.history += [39]
        self.pub.history += [40]
        self.pub.history += [41]
        self.pub.history += [42]
        self.pub.history += [43]
        self.pub.history += [44]
        self.pub.history += [45]
        self.pub.history += [46]
        self.pub.history += [47]
        self.pub.history += [48]
        self.pub.history += [49]
        self.pub.history += [50]
        self.pub.history += [51]
        self.pub.history += [52]
        self.pub.history += [53]
        self.pub.history += [54]
        self.pub.history += [55]
        self.pub.history += [56]
        self.pub.history += [57]
        self.pub.history += [58]
        self.pub.history += [59]
        self.pub.history += [60]
        self.pub.history += [61]
        self.pub.history += [62]
        self.pub.history += [63]
        self.pub.history += [64]
        self.pub.history += [65]
        self.pub.history += [66]
        self.pub.history += [67]
        self.pub.history += [68]
        self.pub.history += [69]
        self.pub.history += [70]
        self.pub.history += [71]
        self.pub.history += [73]
        */

        self.pub.saveHistory()
        self.pub.ballHistoryDraw()
    }
    
    private func nextBall() -> Int {
        var candidate: Array<Int> = []
        for i in 0..<ConstValue.ballCount {
            if self.pub.history.contains(i) == false {
                candidate += [i]
            }
        }
        if candidate.isEmpty {
            return -1    //end
        }
        candidate.shuffle()
        return candidate[0]
    }
        
}
/*
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .environmentObject(PublicManager())
    }
}
*/
//動画用
struct PlayerView: UIViewRepresentable {
    let player: AVPlayer

    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<PlayerView>) {
    }

    func makeUIView(context: Context) -> UIView {
        return PlayerUIView(player: player)
    }

}

HistoryView.swift

//
//  HistoryView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/29.
//

import SwiftUI

struct HistoryView: View {
    @EnvironmentObject var pub: PublicManager
    let cellHeight: CGFloat = 30.0
    let cellWidthRatio: CGFloat = 5.5
    func sellWidth(screenWidth: CGFloat) -> CGFloat {
        return screenWidth / self.cellWidthRatio
    }
    func historyNumber(num1: Int, num2: Int, num3: Int) -> Int {
        return num1 * 25 + num2 * 5 + num3
    }
    
    var body: some View {
        ZStack {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    ZStack {
                        Button(action:{
                            self.pub.isHistory = false
                        }){
                            Text("history")
                                .frame(height: 50)
                                .frame(minWidth: 0, maxWidth: bodyView.size.width, alignment: .center)
                                .background(Color.green)
                                .foregroundColor(Color.white)
                        }
                        HStack {
                            Button(action:{
                                self.pub.isHistory = false
                            }){
                                Image(systemName: "arrow.backward").foregroundColor(.white)
                                    .frame(minWidth: 0, maxWidth: bodyView.size.width / 8, alignment: .center)
                            }.frame(height: 50)
                            Spacer()
                        }
                    }.frame(height: 50)
                    ScrollView {
                        Spacer(minLength: 10)
                        HStack {
                            Spacer()
                            VStack {
                                ForEach(0..<3) { num1 in
                                    VStack {
                                        ForEach(0..<5) { num2 in
                                            HStack(spacing: 0) {
                                                Text(self.pub.historyText[self.historyNumber(num1: num1, num2: num2, num3: 0)])
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.historyColor[self.historyNumber(num1: num1, num2: num2, num3: 0)])
                                                Text(self.pub.historyText[self.historyNumber(num1: num1, num2: num2, num3: 1)])
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.historyColor[self.historyNumber(num1: num1, num2: num2, num3: 1)])
                                                Text(self.pub.historyText[self.historyNumber(num1: num1, num2: num2, num3: 2)])
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.historyColor[self.historyNumber(num1: num1, num2: num2, num3: 2)])
                                                Text(self.pub.historyText[self.historyNumber(num1: num1, num2: num2, num3: 3)])
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.historyColor[self.historyNumber(num1: num1, num2: num2, num3: 3)])
                                                Text(self.pub.historyText[self.historyNumber(num1: num1, num2: num2, num3: 4)])
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.historyColor[self.historyNumber(num1: num1, num2: num2, num3: 4)])
                                            }
                                        }
                                    }
                                }
                            }.border(Color.green, width: 2).frame(maxHeight: .infinity)
                            Spacer()
                        }
                        Spacer(minLength: 150)
                    }
                }
                .background(ConstValue.colorBg)
            }
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
    }
}

struct HistoryView_Previews: PreviewProvider {
    static var previews: some View {
        HistoryView()
            .environmentObject(PublicManager())
    }
}

PlayerUIView.swift

//
//  playerUIView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/28.
//

import SwiftUI
import AVKit

//現時点ではAVPlayerでコントローラーを非表示できないのでAVPlayerを使用する
class PlayerUIView: UIView {
    private let playerLayer = AVPlayerLayer()
    
    init(player: AVPlayer) {
        super.init(frame: .zero)
        playerLayer.player = player
        layer.addSublayer(playerLayer)
        //NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        playerLayer.frame = bounds
    }
    
    //@objc func playerDidFinishPlaying() {
    //    print("#fin#")
    //}
    
}

ProgressView.swift

//
//  ProgressView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/29.
//

import SwiftUI

struct ProgressView: View {
    @EnvironmentObject var pub: PublicManager
    let cellHeaderHeight: CGFloat = 25.0
    let cellHeight: CGFloat = 28.0
    let cellWidthRatio: CGFloat = 5.5
    func sellWidth(screenWidth: CGFloat) -> CGFloat {
        return screenWidth / self.cellWidthRatio
    }
    
    var body: some View {
        ZStack {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    ZStack {
                        Button(action:{
                            self.pub.isProgress = false
                        }){
                            Text("progress")
                                .frame(height: 50)
                                .frame(minWidth: 0, maxWidth: bodyView.size.width, alignment: .center)
                                .background(Color.green)
                                .foregroundColor(Color.white)
                        }
                        HStack {
                            Button(action:{
                                self.pub.isProgress = false
                            }){
                                Image(systemName: "arrow.backward").foregroundColor(.white)
                                    .frame(minWidth: 0, maxWidth: bodyView.size.width / 8, alignment: .center)
                            }.frame(height: 50)
                            Spacer()
                        }
                    }.frame(height: 50)
                    ScrollView {
                        Spacer(minLength: 10)
                        HStack(spacing: 0) {
                            Spacer()
                            VStack {
                                HStack(spacing: 0) {
                                    Text("B").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeaderHeight)
                                        .foregroundColor(Color.white)
                                        .border(Color.green, width: 1)
                                        .background(Color.green)
                                    Text("I").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeaderHeight)
                                        .foregroundColor(Color.white)
                                        .border(Color.green, width: 1)
                                        .background(Color.green)
                                    Text("N").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeaderHeight)
                                        .foregroundColor(Color.white)
                                        .border(Color.green, width: 1)
                                        .background(Color.green)
                                    Text("G").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeaderHeight)
                                        .foregroundColor(Color.white)
                                        .border(Color.green, width: 1)
                                        .background(Color.green)
                                    Text("O").frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeaderHeight)
                                        .foregroundColor(Color.white)
                                        .border(Color.green, width: 1)
                                        .background(Color.green)
                                }
                                ForEach(0..<3) { num1 in
                                    VStack {
                                        ForEach(0..<5) { num2 in
                                            HStack(spacing: 0) {
                                                Text("\(num1 * 5 + num2 + 1)")
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.tableColor[num1 * 5 + num2])
                                                Text("\(num1 * 5 + num2 + 16)")
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.tableColor[num1 * 5 + num2 + 15])
                                                Text("\(num1 * 5 + num2 + 31)")
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.tableColor[num1 * 5 + num2 + 30])
                                                Text("\(num1 * 5 + num2 + 46)")
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.tableColor[num1 * 5 + num2 + 45])
                                                Text("\(num1 * 5 + num2 + 61)")
                                                    .foregroundColor(Color.black)
                                                    .frame(minWidth: self.sellWidth(screenWidth: bodyView.size.width), minHeight:self.cellHeight)
                                                    .border(Color.green, width: 1)
                                                    .background(self.pub.tableColor[num1 * 5 + num2 + 60])
                                            }
                                        }
                                    }
                                }
                            }.border(Color.green, width: 2).frame(maxHeight: .infinity)
                            Spacer()
                        }
                        Spacer(minLength: 150)
                    }
                }
                .background(ConstValue.colorBg)
            }
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true)
    }
}

struct ProgressView_Previews: PreviewProvider {
    static var previews: some View {
        ProgressView().environmentObject(PublicManager())
    }
}

PublicManager.swift

//
//  PublicManager.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/29.
//

import SwiftUI
import GoogleMobileAds

class PublicManager: ObservableObject {
    
    //setting
    @Published var isSetting: Bool = false
    
    //progress
    @Published var isProgress: Bool = false

    //history
    @Published var isHistory: Bool = false

    //card
    @Published var isCard: Bool = false

    //--------------------------------------------------
    //history

    @Published var history: Array<Int> = []

    @Published var tableColor: Array<Color> = [
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
    ]
    @Published var historyColor: Array<Color> = [
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
        ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,ConstValue.colorBg,
    ]
    @Published var historyText: Array<String> = [
        "","","","","",     "","","","","",     "","","","","",
        "","","","","",     "","","","","",     "","","","","",
        "","","","","",     "","","","","",     "","","","","",
        "","","","","",     "","","","","",     "","","","","",
        "","","","","",     "","","","","",     "","","","","",
    ]

    @AppStorage("history0") var history0: Int = -1
    @AppStorage("history1") var history1: Int = -1
    @AppStorage("history2") var history2: Int = -1
    @AppStorage("history3") var history3: Int = -1
    @AppStorage("history4") var history4: Int = -1
    @AppStorage("history5") var history5: Int = -1
    @AppStorage("history6") var history6: Int = -1
    @AppStorage("history7") var history7: Int = -1
    @AppStorage("history8") var history8: Int = -1
    @AppStorage("history9") var history9: Int = -1
    @AppStorage("history10") var history10: Int = -1
    @AppStorage("history11") var history11: Int = -1
    @AppStorage("history12") var history12: Int = -1
    @AppStorage("history13") var history13: Int = -1
    @AppStorage("history14") var history14: Int = -1
    @AppStorage("history15") var history15: Int = -1
    @AppStorage("history16") var history16: Int = -1
    @AppStorage("history17") var history17: Int = -1
    @AppStorage("history18") var history18: Int = -1
    @AppStorage("history19") var history19: Int = -1
    @AppStorage("history20") var history20: Int = -1
    @AppStorage("history21") var history21: Int = -1
    @AppStorage("history22") var history22: Int = -1
    @AppStorage("history23") var history23: Int = -1
    @AppStorage("history24") var history24: Int = -1
    @AppStorage("history25") var history25: Int = -1
    @AppStorage("history26") var history26: Int = -1
    @AppStorage("history27") var history27: Int = -1
    @AppStorage("history28") var history28: Int = -1
    @AppStorage("history29") var history29: Int = -1
    @AppStorage("history30") var history30: Int = -1
    @AppStorage("history31") var history31: Int = -1
    @AppStorage("history32") var history32: Int = -1
    @AppStorage("history33") var history33: Int = -1
    @AppStorage("history34") var history34: Int = -1
    @AppStorage("history35") var history35: Int = -1
    @AppStorage("history36") var history36: Int = -1
    @AppStorage("history37") var history37: Int = -1
    @AppStorage("history38") var history38: Int = -1
    @AppStorage("history39") var history39: Int = -1
    @AppStorage("history40") var history40: Int = -1
    @AppStorage("history41") var history41: Int = -1
    @AppStorage("history42") var history42: Int = -1
    @AppStorage("history43") var history43: Int = -1
    @AppStorage("history44") var history44: Int = -1
    @AppStorage("history45") var history45: Int = -1
    @AppStorage("history46") var history46: Int = -1
    @AppStorage("history47") var history47: Int = -1
    @AppStorage("history48") var history48: Int = -1
    @AppStorage("history49") var history49: Int = -1
    @AppStorage("history50") var history50: Int = -1
    @AppStorage("history51") var history51: Int = -1
    @AppStorage("history52") var history52: Int = -1
    @AppStorage("history53") var history53: Int = -1
    @AppStorage("history54") var history54: Int = -1
    @AppStorage("history55") var history55: Int = -1
    @AppStorage("history56") var history56: Int = -1
    @AppStorage("history57") var history57: Int = -1
    @AppStorage("history58") var history58: Int = -1
    @AppStorage("history59") var history59: Int = -1
    @AppStorage("history60") var history60: Int = -1
    @AppStorage("history61") var history61: Int = -1
    @AppStorage("history62") var history62: Int = -1
    @AppStorage("history63") var history63: Int = -1
    @AppStorage("history64") var history64: Int = -1
    @AppStorage("history65") var history65: Int = -1
    @AppStorage("history66") var history66: Int = -1
    @AppStorage("history67") var history67: Int = -1
    @AppStorage("history68") var history68: Int = -1
    @AppStorage("history69") var history69: Int = -1
    @AppStorage("history70") var history70: Int = -1
    @AppStorage("history71") var history71: Int = -1
    @AppStorage("history72") var history72: Int = -1
    @AppStorage("history73") var history73: Int = -1
    @AppStorage("history74") var history74: Int = -1

    func clearHistory() {
        self.history = []
        self.history0 = -1
        self.history1 = -1
        self.history2 = -1
        self.history3 = -1
        self.history4 = -1
        self.history5 = -1
        self.history6 = -1
        self.history7 = -1
        self.history8 = -1
        self.history9 = -1
        self.history10 = -1
        self.history11 = -1
        self.history12 = -1
        self.history13 = -1
        self.history14 = -1
        self.history15 = -1
        self.history16 = -1
        self.history17 = -1
        self.history18 = -1
        self.history19 = -1
        self.history20 = -1
        self.history21 = -1
        self.history22 = -1
        self.history23 = -1
        self.history24 = -1
        self.history25 = -1
        self.history26 = -1
        self.history27 = -1
        self.history28 = -1
        self.history29 = -1
        self.history30 = -1
        self.history31 = -1
        self.history32 = -1
        self.history33 = -1
        self.history34 = -1
        self.history35 = -1
        self.history36 = -1
        self.history37 = -1
        self.history38 = -1
        self.history39 = -1
        self.history40 = -1
        self.history41 = -1
        self.history42 = -1
        self.history43 = -1
        self.history44 = -1
        self.history45 = -1
        self.history46 = -1
        self.history47 = -1
        self.history48 = -1
        self.history49 = -1
        self.history50 = -1
        self.history51 = -1
        self.history52 = -1
        self.history53 = -1
        self.history54 = -1
        self.history55 = -1
        self.history56 = -1
        self.history57 = -1
        self.history58 = -1
        self.history59 = -1
        self.history60 = -1
        self.history61 = -1
        self.history62 = -1
        self.history63 = -1
        self.history64 = -1
        self.history65 = -1
        self.history66 = -1
        self.history67 = -1
        self.history68 = -1
        self.history69 = -1
        self.history70 = -1
        self.history71 = -1
        self.history72 = -1
        self.history73 = -1
        self.history74 = -1
    }
    
    func ballHistoryDraw() {
        for i in 0..<ConstValue.ballCount {
            let c: Color = self.history.contains(i) ? ConstValue.colorOpen : ConstValue.colorBg
            self.tableColor[i] = c
        }
        if self.history.isEmpty == false {
            self.tableColor[self.history[self.history.count - 1]] = ConstValue.colorOpenLast
        }
        for i in 0..<ConstValue.ballCount {
            if self.history.count > i {
                self.historyText[i] = String(self.history[i] + 1)
                let c: Color = (self.history.count == i + 1) ? ConstValue.colorOpenLast : ConstValue.colorOpen
                self.historyColor[i] = c
            } else {
                self.historyText[i] = ""
                self.historyColor[i] = ConstValue.colorBg
            }
        }
    }

    func loadHistory() {
        self.history = []
        if self.history0 != -1 {
            self.history += [self.history0]
        }
        if self.history1 != -1 {
            self.history += [self.history1]
        }
        if self.history2 != -1 {
            self.history += [self.history2]
        }
        if self.history3 != -1 {
            self.history += [self.history3]
        }
        if self.history4 != -1 {
            self.history += [self.history4]
        }
        if self.history5 != -1 {
            self.history += [self.history5]
        }
        if self.history6 != -1 {
            self.history += [self.history6]
        }
        if self.history7 != -1 {
            self.history += [self.history7]
        }
        if self.history8 != -1 {
            self.history += [self.history8]
        }
        if self.history9 != -1 {
            self.history += [self.history9]
        }
        if self.history10 != -1 {
            self.history += [self.history10]
        }
        if self.history11 != -1 {
            self.history += [self.history11]
        }
        if self.history12 != -1 {
            self.history += [self.history12]
        }
        if self.history13 != -1 {
            self.history += [self.history13]
        }
        if self.history14 != -1 {
            self.history += [self.history14]
        }
        if self.history15 != -1 {
            self.history += [self.history15]
        }
        if self.history16 != -1 {
            self.history += [self.history16]
        }
        if self.history17 != -1 {
            self.history += [self.history17]
        }
        if self.history18 != -1 {
            self.history += [self.history18]
        }
        if self.history19 != -1 {
            self.history += [self.history19]
        }
        if self.history20 != -1 {
            self.history += [self.history20]
        }
        if self.history21 != -1 {
            self.history += [self.history21]
        }
        if self.history22 != -1 {
            self.history += [self.history22]
        }
        if self.history23 != -1 {
            self.history += [self.history23]
        }
        if self.history24 != -1 {
            self.history += [self.history24]
        }
        if self.history25 != -1 {
            self.history += [self.history25]
        }
        if self.history26 != -1 {
            self.history += [self.history26]
        }
        if self.history27 != -1 {
            self.history += [self.history27]
        }
        if self.history28 != -1 {
            self.history += [self.history28]
        }
        if self.history29 != -1 {
            self.history += [self.history29]
        }
        if self.history30 != -1 {
            self.history += [self.history30]
        }
        if self.history31 != -1 {
            self.history += [self.history31]
        }
        if self.history32 != -1 {
            self.history += [self.history32]
        }
        if self.history33 != -1 {
            self.history += [self.history33]
        }
        if self.history34 != -1 {
            self.history += [self.history34]
        }
        if self.history35 != -1 {
            self.history += [self.history35]
        }
        if self.history36 != -1 {
            self.history += [self.history36]
        }
        if self.history37 != -1 {
            self.history += [self.history37]
        }
        if self.history38 != -1 {
            self.history += [self.history38]
        }
        if self.history39 != -1 {
            self.history += [self.history39]
        }
        if self.history40 != -1 {
            self.history += [self.history40]
        }
        if self.history41 != -1 {
            self.history += [self.history41]
        }
        if self.history42 != -1 {
            self.history += [self.history42]
        }
        if self.history43 != -1 {
            self.history += [self.history43]
        }
        if self.history44 != -1 {
            self.history += [self.history44]
        }
        if self.history45 != -1 {
            self.history += [self.history45]
        }
        if self.history46 != -1 {
            self.history += [self.history46]
        }
        if self.history47 != -1 {
            self.history += [self.history47]
        }
        if self.history48 != -1 {
            self.history += [self.history48]
        }
        if self.history49 != -1 {
            self.history += [self.history49]
        }
        if self.history50 != -1 {
            self.history += [self.history50]
        }
        if self.history51 != -1 {
            self.history += [self.history51]
        }
        if self.history52 != -1 {
            self.history += [self.history52]
        }
        if self.history53 != -1 {
            self.history += [self.history53]
        }
        if self.history54 != -1 {
            self.history += [self.history54]
        }
        if self.history55 != -1 {
            self.history += [self.history55]
        }
        if self.history56 != -1 {
            self.history += [self.history56]
        }
        if self.history57 != -1 {
            self.history += [self.history57]
        }
        if self.history58 != -1 {
            self.history += [self.history58]
        }
        if self.history59 != -1 {
            self.history += [self.history59]
        }
        if self.history60 != -1 {
            self.history += [self.history60]
        }
        if self.history61 != -1 {
            self.history += [self.history61]
        }
        if self.history62 != -1 {
            self.history += [self.history62]
        }
        if self.history63 != -1 {
            self.history += [self.history63]
        }
        if self.history64 != -1 {
            self.history += [self.history64]
        }
        if self.history65 != -1 {
            self.history += [self.history65]
        }
        if self.history66 != -1 {
            self.history += [self.history66]
        }
        if self.history67 != -1 {
            self.history += [self.history67]
        }
        if self.history68 != -1 {
            self.history += [self.history68]
        }
        if self.history69 != -1 {
            self.history += [self.history69]
        }
        if self.history70 != -1 {
            self.history += [self.history70]
        }
        if self.history71 != -1 {
            self.history += [self.history71]
        }
        if self.history72 != -1 {
            self.history += [self.history72]
        }
        if self.history73 != -1 {
            self.history += [self.history73]
        }
        if self.history74 != -1 {
            self.history += [self.history74]
        }
    }

    func saveHistory() {
        let nextBall: Int = self.history[self.history.count - 1]
        switch self.history.count {
        case 1: self.history0 = nextBall
        case 2: self.history1 = nextBall
        case 3: self.history2 = nextBall
        case 4: self.history3 = nextBall
        case 5: self.history4 = nextBall
        case 6: self.history5 = nextBall
        case 7: self.history6 = nextBall
        case 8: self.history7 = nextBall
        case 9: self.history8 = nextBall
        case 10: self.history9 = nextBall
        case 11: self.history10 = nextBall
        case 12: self.history11 = nextBall
        case 13: self.history12 = nextBall
        case 14: self.history13 = nextBall
        case 15: self.history14 = nextBall
        case 16: self.history15 = nextBall
        case 17: self.history16 = nextBall
        case 18: self.history17 = nextBall
        case 19: self.history18 = nextBall
        case 20: self.history19 = nextBall
        case 21: self.history20 = nextBall
        case 22: self.history21 = nextBall
        case 23: self.history22 = nextBall
        case 24: self.history23 = nextBall
        case 25: self.history24 = nextBall
        case 26: self.history25 = nextBall
        case 27: self.history26 = nextBall
        case 28: self.history27 = nextBall
        case 29: self.history28 = nextBall
        case 30: self.history29 = nextBall
        case 31: self.history30 = nextBall
        case 32: self.history31 = nextBall
        case 33: self.history32 = nextBall
        case 34: self.history33 = nextBall
        case 35: self.history34 = nextBall
        case 36: self.history35 = nextBall
        case 37: self.history36 = nextBall
        case 38: self.history37 = nextBall
        case 39: self.history38 = nextBall
        case 40: self.history39 = nextBall
        case 41: self.history40 = nextBall
        case 42: self.history41 = nextBall
        case 43: self.history42 = nextBall
        case 44: self.history43 = nextBall
        case 45: self.history44 = nextBall
        case 46: self.history45 = nextBall
        case 47: self.history46 = nextBall
        case 48: self.history47 = nextBall
        case 49: self.history48 = nextBall
        case 50: self.history49 = nextBall
        case 51: self.history50 = nextBall
        case 52: self.history51 = nextBall
        case 53: self.history52 = nextBall
        case 54: self.history53 = nextBall
        case 55: self.history54 = nextBall
        case 56: self.history55 = nextBall
        case 57: self.history56 = nextBall
        case 58: self.history57 = nextBall
        case 59: self.history58 = nextBall
        case 60: self.history59 = nextBall
        case 61: self.history60 = nextBall
        case 62: self.history61 = nextBall
        case 63: self.history62 = nextBall
        case 64: self.history63 = nextBall
        case 65: self.history64 = nextBall
        case 66: self.history65 = nextBall
        case 67: self.history66 = nextBall
        case 68: self.history67 = nextBall
        case 69: self.history68 = nextBall
        case 70: self.history69 = nextBall
        case 71: self.history70 = nextBall
        case 72: self.history71 = nextBall
        case 73: self.history72 = nextBall
        case 74: self.history73 = nextBall
        case 75: self.history74 = nextBall
        default: break
        }
    }
    
    //--------------------------------------------------
    //card
    
    @Published var cardText: Array<Int> = [
        0,0,0,0,0,
        0,0,0,0,0,
        0,0,0,0,0,
        0,0,0,0,0,
        0,0,0,0,0,
    ]
    @Published var cardOpen: Array<Bool> = [
        false,false,false,false,false,
        false,false,false,false,false,
        false,false,false,false,false,
        false,false,false,false,false,
        false,false,false,false,false,
    ]
    
    @AppStorage("cardText0") var cardText0: Int = 0
    @AppStorage("cardText1") var cardText1: Int = 0
    @AppStorage("cardText2") var cardText2: Int = 0
    @AppStorage("cardText3") var cardText3: Int = 0
    @AppStorage("cardText4") var cardText4: Int = 0
    @AppStorage("cardText5") var cardText5: Int = 0
    @AppStorage("cardText6") var cardText6: Int = 0
    @AppStorage("cardText7") var cardText7: Int = 0
    @AppStorage("cardText8") var cardText8: Int = 0
    @AppStorage("cardText9") var cardText9: Int = 0
    @AppStorage("cardText10") var cardText10: Int = 0
    @AppStorage("cardText11") var cardText11: Int = 0
    @AppStorage("cardText12") var cardText12: Int = 0
    @AppStorage("cardText13") var cardText13: Int = 0
    @AppStorage("cardText14") var cardText14: Int = 0
    @AppStorage("cardText15") var cardText15: Int = 0
    @AppStorage("cardText16") var cardText16: Int = 0
    @AppStorage("cardText17") var cardText17: Int = 0
    @AppStorage("cardText18") var cardText18: Int = 0
    @AppStorage("cardText19") var cardText19: Int = 0
    @AppStorage("cardText20") var cardText20: Int = 0
    @AppStorage("cardText21") var cardText21: Int = 0
    @AppStorage("cardText22") var cardText22: Int = 0
    @AppStorage("cardText23") var cardText23: Int = 0
    @AppStorage("cardText24") var cardText24: Int = 0

    @AppStorage("cardOpen0") var cardOpen0: Bool = false
    @AppStorage("cardOpen1") var cardOpen1: Bool = false
    @AppStorage("cardOpen2") var cardOpen2: Bool = false
    @AppStorage("cardOpen3") var cardOpen3: Bool = false
    @AppStorage("cardOpen4") var cardOpen4: Bool = false
    @AppStorage("cardOpen5") var cardOpen5: Bool = false
    @AppStorage("cardOpen6") var cardOpen6: Bool = false
    @AppStorage("cardOpen7") var cardOpen7: Bool = false
    @AppStorage("cardOpen8") var cardOpen8: Bool = false
    @AppStorage("cardOpen9") var cardOpen9: Bool = false
    @AppStorage("cardOpen10") var cardOpen10: Bool = false
    @AppStorage("cardOpen11") var cardOpen11: Bool = false
    @AppStorage("cardOpen12") var cardOpen12: Bool = false
    @AppStorage("cardOpen13") var cardOpen13: Bool = false
    @AppStorage("cardOpen14") var cardOpen14: Bool = false
    @AppStorage("cardOpen15") var cardOpen15: Bool = false
    @AppStorage("cardOpen16") var cardOpen16: Bool = false
    @AppStorage("cardOpen17") var cardOpen17: Bool = false
    @AppStorage("cardOpen18") var cardOpen18: Bool = false
    @AppStorage("cardOpen19") var cardOpen19: Bool = false
    @AppStorage("cardOpen20") var cardOpen20: Bool = false
    @AppStorage("cardOpen21") var cardOpen21: Bool = false
    @AppStorage("cardOpen22") var cardOpen22: Bool = false
    @AppStorage("cardOpen23") var cardOpen23: Bool = false
    @AppStorage("cardOpen24") var cardOpen24: Bool = false

    func clearCard() {
        for i in 0..<25 {
            self.cardText[i] = 0
            self.cardOpen[i] = false
        }
        self.cardText0 = 0
    }
    
    func loadCard() {
        if self.cardText0 == 0 {    //初回
            var nums1: Array<Int> = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
            var nums2: Array<Int> = [16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
            var nums3: Array<Int> = [31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]
            var nums4: Array<Int> = [46,47,48,49,50,51,52,53,54,55,56,57,58,59,60]
            var nums5: Array<Int> = [61,62,63,64,65,66,67,68,69,70,71,72,73,74,75]
            nums1.shuffle()
            nums2.shuffle()
            nums3.shuffle()
            nums4.shuffle()
            nums5.shuffle()
            self.cardText0 = nums1[0]
            self.cardText5 = nums1[1]
            self.cardText10 = nums1[2]
            self.cardText15 = nums1[3]
            self.cardText20 = nums1[4]
            self.cardText1 = nums2[0]
            self.cardText6 = nums2[1]
            self.cardText11 = nums2[2]
            self.cardText16 = nums2[3]
            self.cardText21 = nums2[4]
            self.cardText2 = nums3[0]
            self.cardText7 = nums3[1]
            self.cardText12 = nums3[2]
            self.cardText17 = nums3[3]
            self.cardText22 = nums3[4]
            self.cardText3 = nums4[0]
            self.cardText8 = nums4[1]
            self.cardText13 = nums4[2]
            self.cardText18 = nums4[3]
            self.cardText23 = nums4[4]
            self.cardText4 = nums5[0]
            self.cardText9 = nums5[1]
            self.cardText14 = nums5[2]
            self.cardText19 = nums5[3]
            self.cardText24 = nums5[4]
            self.cardOpen0 = false
            self.cardOpen1 = false
            self.cardOpen2 = false
            self.cardOpen3 = false
            self.cardOpen4 = false
            self.cardOpen5 = false
            self.cardOpen6 = false
            self.cardOpen7 = false
            self.cardOpen8 = false
            self.cardOpen9 = false
            self.cardOpen10 = false
            self.cardOpen11 = false
            self.cardOpen12 = false
            self.cardOpen13 = false
            self.cardOpen14 = false
            self.cardOpen15 = false
            self.cardOpen16 = false
            self.cardOpen17 = false
            self.cardOpen18 = false
            self.cardOpen19 = false
            self.cardOpen20 = false
            self.cardOpen21 = false
            self.cardOpen22 = false
            self.cardOpen23 = false
            self.cardOpen24 = false
        }
        self.cardText[0] = self.cardText0
        self.cardText[1] = self.cardText1
        self.cardText[2] = self.cardText2
        self.cardText[3] = self.cardText3
        self.cardText[4] = self.cardText4
        self.cardText[5] = self.cardText5
        self.cardText[6] = self.cardText6
        self.cardText[7] = self.cardText7
        self.cardText[8] = self.cardText8
        self.cardText[9] = self.cardText9
        self.cardText[10] = self.cardText10
        self.cardText[11] = self.cardText11
        self.cardText[12] = self.cardText12
        self.cardText[13] = self.cardText13
        self.cardText[14] = self.cardText14
        self.cardText[15] = self.cardText15
        self.cardText[16] = self.cardText16
        self.cardText[17] = self.cardText17
        self.cardText[18] = self.cardText18
        self.cardText[19] = self.cardText19
        self.cardText[20] = self.cardText20
        self.cardText[21] = self.cardText21
        self.cardText[22] = self.cardText22
        self.cardText[23] = self.cardText23
        self.cardText[24] = self.cardText24
        //
        self.cardOpen[0] = self.cardOpen0
        self.cardOpen[1] = self.cardOpen1
        self.cardOpen[2] = self.cardOpen2
        self.cardOpen[3] = self.cardOpen3
        self.cardOpen[4] = self.cardOpen4
        self.cardOpen[5] = self.cardOpen5
        self.cardOpen[6] = self.cardOpen6
        self.cardOpen[7] = self.cardOpen7
        self.cardOpen[8] = self.cardOpen8
        self.cardOpen[9] = self.cardOpen9
        self.cardOpen[10] = self.cardOpen10
        self.cardOpen[11] = self.cardOpen11
        self.cardOpen[12] = self.cardOpen12
        self.cardOpen[13] = self.cardOpen13
        self.cardOpen[14] = self.cardOpen14
        self.cardOpen[15] = self.cardOpen15
        self.cardOpen[16] = self.cardOpen16
        self.cardOpen[17] = self.cardOpen17
        self.cardOpen[18] = self.cardOpen18
        self.cardOpen[19] = self.cardOpen19
        self.cardOpen[20] = self.cardOpen20
        self.cardOpen[21] = self.cardOpen21
        self.cardOpen[22] = self.cardOpen22
        self.cardOpen[23] = self.cardOpen23
        self.cardOpen[24] = self.cardOpen24
    }

    func saveCard() {
        self.cardText0 = self.cardText[0]
        self.cardText1 = self.cardText[1]
        self.cardText2 = self.cardText[2]
        self.cardText3 = self.cardText[3]
        self.cardText4 = self.cardText[4]
        self.cardText5 = self.cardText[5]
        self.cardText6 = self.cardText[6]
        self.cardText7 = self.cardText[7]
        self.cardText8 = self.cardText[8]
        self.cardText9 = self.cardText[9]
        self.cardText10 = self.cardText[10]
        self.cardText11 = self.cardText[11]
        self.cardText12 = self.cardText[12]
        self.cardText13 = self.cardText[13]
        self.cardText14 = self.cardText[14]
        self.cardText15 = self.cardText[15]
        self.cardText16 = self.cardText[16]
        self.cardText17 = self.cardText[17]
        self.cardText18 = self.cardText[18]
        self.cardText19 = self.cardText[19]
        self.cardText20 = self.cardText[20]
        self.cardText21 = self.cardText[21]
        self.cardText22 = self.cardText[22]
        self.cardText23 = self.cardText[23]
        self.cardText24 = self.cardText[24]
        //
        self.cardOpen0 = self.cardOpen[0]
        self.cardOpen1 = self.cardOpen[1]
        self.cardOpen2 = self.cardOpen[2]
        self.cardOpen3 = self.cardOpen[3]
        self.cardOpen4 = self.cardOpen[4]
        self.cardOpen5 = self.cardOpen[5]
        self.cardOpen6 = self.cardOpen[6]
        self.cardOpen7 = self.cardOpen[7]
        self.cardOpen8 = self.cardOpen[8]
        self.cardOpen9 = self.cardOpen[9]
        self.cardOpen10 = self.cardOpen[10]
        self.cardOpen11 = self.cardOpen[11]
        self.cardOpen12 = self.cardOpen[12]
        self.cardOpen13 = self.cardOpen[13]
        self.cardOpen14 = self.cardOpen[14]
        self.cardOpen15 = self.cardOpen[15]
        self.cardOpen16 = self.cardOpen[16]
        self.cardOpen17 = self.cardOpen[17]
        self.cardOpen18 = self.cardOpen[18]
        self.cardOpen19 = self.cardOpen[19]
        self.cardOpen20 = self.cardOpen[20]
        self.cardOpen21 = self.cardOpen[21]
        self.cardOpen22 = self.cardOpen[22]
        self.cardOpen23 = self.cardOpen[23]
        self.cardOpen24 = self.cardOpen[24]
    }
    

    //--------------------------------------------------
    //adMob
    
    struct AdView: UIViewRepresentable {
        func makeUIView(context: Context) -> GADBannerView {
            let banner = GADBannerView(adSize: kGADAdSizeBanner)
            #if DEBUG
            banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
            #else
            banner.adUnitID = "ca-app-pub-0000000000000000/0000000000"
            #endif
            banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
            banner.load(GADRequest())
            return banner
        }

        func updateUIView(_ uiView: GADBannerView, context: Context) {
        }
    }

    //--------------------------------------------------

}

SettingView.swift

//
//  SettingView.swift
//  BingoMachine
//
//  Created by akira ohmachi on 2021/03/27.
//

import SwiftUI

struct SettingView: View {
    @EnvironmentObject var pub: PublicManager
    @State private var resetFacilitator: Bool = false
    @State private var resetParticipant: Bool = false

    var body: some View {
        VStack() {
            HStack {
                Button(action: {
                    self.pub.isSetting = false
                }) {
                    Image(systemName: "arrow.backward")
                    Text("cancel")
                }
                Spacer()
                Button(action: {
                    if self.resetFacilitator {
                        self.pub.clearHistory()
                        self.pub.ballHistoryDraw()
                    }
                    if self.resetParticipant {
                        self.pub.clearCard()
                        self.pub.loadCard()
                    }
                    self.pub.isSetting = false
                }) {
                    HStack {
                        Text("apply")
                        Image(systemName: "checkmark.circle")
                    }
                }
            }
            .padding(20)
        }
        Form {
            Section {
                Toggle(isOn: self.$resetFacilitator) {
                    Text("resetFacilitator")
                        .font(.subheadline)
                }
                Text("resetFacilitatorNote")
                    .font(.footnote)
            }
            Section {
                Toggle(isOn: self.$resetParticipant) {
                    Text("resetParticipant")
                        .font(.subheadline)
                }
                Text("resetParticipantNote")
                    .font(.footnote)
            }
            Section {
                Text("usage")
                    .font(.footnote)
                Text("usage1")
                    .font(.footnote)
            }
            Section {
                Text("usageFacilitator")
                    .font(.footnote)
                Text("usageFacilitator1")
                    .font(.footnote)
            }
            Section {
                Text("usageParticipant")
                    .font(.footnote)
                Text("usageParticipant1")
                    .font(.footnote)
            }
            Section {
                Text("usageNote")
                    .font(.footnote)
            }
        }
        //.navigationBarTitle("Setting",displayMode: .automatic)
        //.navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
    }
}

struct SettingView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            SettingView().environmentObject(PublicManager())
        }
    }
}