IEには対応していません。Edgeでサイトを開く ≫

ソースコード source code

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

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

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

ConstValue.swift

//
//  ConstValue.swift
//  NumberRoulette
//
//  Created by akira ohmachi on 2021/04/06.
//

import SwiftUI

class ConstValue: ObservableObject {
    
    //background
    static let colorBg: Color = Color.init(red:0.59,green:0.51,blue:0.33)
    
    //button color
    static let colorStart: Color = Color.init(red:0.238, green:0.77, blue:0.387)
    static let colorSetting: Color = Color.init(red:0.543, green:0.77, blue:0.289)
  
    static let colorArcArray: Array<Color> = [
            Color.init(red: 234 / 256, green: 123 / 256, blue: 132 / 256),
            Color.init(red: 240 / 256, green: 196 / 256, blue: 123 / 256),
            Color.init(red: 247 / 256, green: 239 / 256, blue: 123 / 256),
            Color.init(red: 192 / 256, green: 217 / 256, blue: 139 / 256),
            Color.init(red: 123 / 256, green: 197 / 256, blue: 156 / 256),
            Color.init(red: 123 / 256, green: 201 / 256, blue: 235 / 256),
            Color.init(red: 123 / 256, green: 173 / 256, blue: 211 / 256),
            Color.init(red: 138 / 256, green: 139 / 256, blue: 189 / 256),
            Color.init(red: 194 / 256, green: 127 / 256, blue: 186 / 256),
            Color.init(red: 233 / 256, green: 123 / 256, blue: 185 / 256),
    ]
    static let colorArcs: Array<Color> = [
        colorArcArray[0],
        colorArcArray[2],
        colorArcArray[4],
        colorArcArray[6],
        colorArcArray[8],
        colorArcArray[1],
        colorArcArray[3],
        colorArcArray[5],
        colorArcArray[7],
        colorArcArray[9],
        colorArcArray[0],
        colorArcArray[2],
        colorArcArray[4],
        colorArcArray[6],
        colorArcArray[8],
        colorArcArray[1],
        colorArcArray[3],
        colorArcArray[5],
        colorArcArray[7],
        colorArcArray[9],
    ]

    static let colorArcDarkArray: Array<Color> = [
            Color.init(red: 222 / 256, green:   0 / 256, blue:  17 / 256),
            Color.init(red: 234 / 256, green: 145 / 256, blue:   0 / 256),
            Color.init(red: 247 / 256, green: 232 / 256, blue:   0 / 256),
            Color.init(red: 137 / 256, green: 188 / 256, blue:  30 / 256),
            Color.init(red:   0 / 256, green: 147 / 256, blue:  66 / 256),
            Color.init(red:   0 / 256, green: 154 / 256, blue: 225 / 256),
            Color.init(red:   0 / 256, green: 101 / 256, blue: 176 / 256),
            Color.init(red:  28 / 256, green:  31 / 256, blue: 131 / 256),
            Color.init(red: 140 / 256, green:   7 / 256, blue: 126 / 256),
            Color.init(red: 220 / 256, green:   0 / 256, blue: 123 / 256),
    ]

    static let colorArcDarks: Array<Color> = [
        colorArcDarkArray[0],
        colorArcDarkArray[2],
        colorArcDarkArray[4],
        colorArcDarkArray[6],
        colorArcDarkArray[8],
        colorArcDarkArray[1],
        colorArcDarkArray[3],
        colorArcDarkArray[5],
        colorArcDarkArray[7],
        colorArcDarkArray[9],
        colorArcDarkArray[0],
        colorArcDarkArray[2],
        colorArcDarkArray[4],
        colorArcDarkArray[6],
        colorArcDarkArray[8],
        colorArcDarkArray[1],
        colorArcDarkArray[3],
        colorArcDarkArray[5],
        colorArcDarkArray[7],
        colorArcDarkArray[9],
    ]

}

ContentView.swift

//
//  ContentView.swift
//  NumberRoulette
//
//  Created by akira ohmachi on 2021/04/06.
//

import SwiftUI

struct ContentView: View {
    @EnvironmentObject var pub: PublicManager
    @State private var choiceResult: String = ""
    @State private var busyFlag: Bool = false
    @State private var destroyFlag: Bool = false
    @State private var colorBg: Color = Color.white
    @State private var itemRateSum: Int = 0
    @State private var actionState: Int = 0
    @State private var actionCount: Int = 0
    @State private var actionAngle: Double = 0.0
    struct ArcState {
        var start: Double
        var end: Double
        var color1: Color
        var color2: Color
        var name: String
        init(start: Double, end: Double, color1: Color, color2: Color, name: String) {
            self.start = start
            self.end = end
            self.color1 = color1
            self.color2 = color2
            self.name = name
        }
        func isDraw() -> Bool {
            if self.start == 0.0 && self.end == 0.0 {
                return false
            }
            return true
        }
        mutating func setHidden() {
            self.start = 0.0
            self.end = 0.0
        }
    }
    //start=0,end=0の場合は描画しない
    @State private var arcs: Array<ArcState> = [
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),

        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
        ArcState(start: 0, end: 0, color1: Color.black, color2: Color.black, name: ""),
    ]
    
    //doubleを入力用stringに変換
    func itemRatioValue(num: Double) -> String {
        if num == 0.0 {
            return ""
        } else {
            let numInt: Int = Int(num)
            if Double(numInt) == num {
                return String(numInt)
            } else {
                return String(num)
            }
        }
    }
    
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startRoulette()
                        }){
                            Text("start")
                                .frame(width: bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                                .font(.title2)
                        }
                        Rectangle().fill(Color.white).frame(width: 2, height: bodyView.size.height / 6)
                        NavigationLink(destination: SettingView(),isActive: self.$pub.isSetting) {
                            Button(action:{
                                if (self.busyFlag) {
                                    return
                                }
                                self.pub.tmpNumberMin = String(self.pub.numberMin)
                                self.pub.tmpNumberMax = String(self.pub.numberMax)
                                self.pub.tmpNumberReverse = self.pub.numberReverse
                                self.pub.tmpNumberRandom = self.pub.numberRandom
                                self.pub.tmpShortTime = self.pub.shortTime
                                self.pub.isSetting = true
                            }){
                                Text("setting")
                                    .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                    .background(ConstValue.colorSetting)
                                    .foregroundColor(Color.white)
                                    .font(.title2)
                            }
                        }
                    }
                    .frame(width: bodyView.size.width, height: bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width, height: 2)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            Spacer(minLength: bodyView.size.height / 40)
                            Text(self.choiceResult).animation(.none)
                            Spacer(minLength: bodyView.size.height / 40)
                            ZStack {
                                self.baseArc(size: bodyView.size.width)
                                ForEach(0..<self.arcs.count) {
                                    if self.arcs[$0].isDraw() {
                                        self.fillArc(start: self.arcs[$0].start, end: self.arcs[$0].end, color1: self.arcs[$0].color1, color2: self.arcs[$0].color2, size: bodyView.size.width)
                                    }
                                }
                                ForEach(0..<self.arcs.count) {
                                    if self.arcs[$0].isDraw() {
                                        self.arcText(start: self.arcs[$0].start, end: self.arcs[$0].end, name: arcs[$0].name, size: bodyView.size.width)
                                    }
                                }
                            }
                            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(self.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .onAppear {     //アプリ起動時に実行
            self.initItemData()
            self.drawRoulette()
        }
        .onChange(of: self.pub.isSetting) { _ in    //SettingViewからの戻り
            if self.pub.isSetting == false {
                self.initItemData()
                self.drawRoulette()
            }
        }
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }

    private func startRoulette() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        self.initItemData()
        self.actionState = 0
        self.actionCount = 0
        self.actionTimeline()
    }

    private func initItemData() {
        if self.pub.numberMin > self.pub.numberMax {
            let tmp: Int = self.pub.numberMin
            self.pub.numberMin = self.pub.numberMax
            self.pub.numberMax = tmp
        } else if self.pub.numberMin == self.pub.numberMax {
            self.pub.numberMax += 1
        }
        self.pub.numberMax = min(self.pub.numberMax, self.pub.numberMin + self.arcs.count - 1)
        //合計値
        self.itemRateSum = self.pub.numberMax - self.pub.numberMin + 1
        //数字用意
        var numbers: Array<Int> = []
        var c: Int = 0
        for i in self.pub.numberMin ... self.pub.numberMax {
            numbers.append(i)
            c += 1
        }
        if self.pub.numberRandom {
            numbers = numbers.shuffled()
        } else if self.pub.numberReverse {
            numbers = numbers.reversed()
        }
        //Viewの状態を初期化
        for i in 0..<self.arcs.count {
            self.arcs[i].setHidden()
        }
        //Viewの値をセット
        for i in 0..<numbers.count {
            self.arcs[i].color1 = ConstValue.colorArcs[i % 10]
            self.arcs[i].color2 = ConstValue.colorArcDarks[i % 10]
            self.arcs[i].name = String(numbers[i])
        }
    }
    
    //animation
    private func actionTimeline() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.drawRoulette()
            if self.actionState == 0 {
                self.actionAngle += Double(self.actionCount)
                self.actionCount += 1
                if self.actionCount > 50 {
                    self.actionAngle = self.actionAngle.truncatingRemainder(dividingBy: 360.0)
                    self.actionCount = 0
                    if self.pub.shortTime {
                        self.actionCount = 50
                    }
                    self.actionState = 1
                }
            } else if self.actionState == 1 {
                self.actionAngle += 89.7 + Double(self.actionCount / 10)
                self.actionCount += 1
                if self.actionCount > 50 {
                    self.actionAngle += Double.random(in: 0..<360.0)
                    self.actionAngle = self.actionAngle.truncatingRemainder(dividingBy: 360.0)
                    self.actionCount = 0
                    if self.pub.shortTime {
                        self.actionCount = 150
                    }
                    self.actionState = 2
                }
            } else if self.actionState == 2 {
                self.actionAngle += 100.0 - Double(self.actionCount / 2)
                self.actionCount += 1
                if self.actionCount > 200 {
                    self.actionAngle = self.actionAngle.truncatingRemainder(dividingBy: 360.0)
                    self.actionCount = 0
                    self.actionState = 3
                }
            } else if self.actionState == 3 {
                self.busyFlag = false
                return
            }
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.actionTimeline()
                    }
                }
            }
        }
    }
    
    private func drawRoulette() {
        var startAngle: Double = self.actionAngle
        let currentAngle: Double = 360.0 / Double(self.itemRateSum)   //書こうとする扇形の確度
        //判定結果計算
        var nowSelectItem: Int = -1
        for i in 0..<self.itemRateSum {
            let startAngleTmp: Double = startAngle.truncatingRemainder(dividingBy: 360.0)
            if ((startAngleTmp <= 270.0) && (startAngleTmp + currentAngle > 270.0)) || ((startAngleTmp >= 270.0) && (startAngleTmp + currentAngle >= 630.0)) {
                nowSelectItem = i
                break
            }
            startAngle += currentAngle
        }
        //判定結果表示 back color
        if nowSelectItem != -1 {  //念のため
            self.colorBg = ConstValue.colorArcs[nowSelectItem % 10]
        }
        //円グラフ
        startAngle = self.actionAngle
        for i in 0..<self.itemRateSum {
            //circle
            self.arcs[i].start = startAngle
            self.arcs[i].end = startAngle + currentAngle
            //
            startAngle += currentAngle
        }
        //判定結果表示 text
        if (nowSelectItem != -1) {  //念のため
            self.choiceResult = self.arcs[nowSelectItem].name
        }
    }
    
    private func baseArc(size: CGFloat) -> some View {
        return Arc(startAngle: .degrees(-89.5), endAngle: .degrees(269.5))
            .fill(Color.white)
            .frame(width: size * 0.9, height: size * 0.9, alignment: .center)
            .animation(.none)
    }

    private func fillArc(start: Double, end: Double, color1: Color, color2: Color, size: CGFloat) -> some View {
        return ZStack {
            Arc(startAngle: .degrees(start), endAngle: .degrees(end))
                .fill(color1)
                .frame(width: size * 0.85, height: size * 0.85, alignment: .center)
                .animation(.none)
            Arc(startAngle: .degrees(start), endAngle: .degrees(end))
                .fill(color2)
                .frame(width: size * 0.5, height: size * 0.5, alignment: .center)
                .animation(.none)
        }
    }
    
    private func arcText(start: Double, end: Double, name: String, size: CGFloat) -> some View {
        let textAngle: CGFloat = CGFloat(((start + end) / 2.0)) + 90.0
        let textX: CGFloat = CGFloat(sin(textAngle * CGFloat.pi / 180) * (size / 3))
        let textY: CGFloat = CGFloat(cos(textAngle * CGFloat.pi / 180) * (size / 3) * -1)
        return ZStack {
            Text(name)
                .offset(x: textX, y: textY)
                .font(.footnote)
                .animation(.none)
        }
    }

}

struct Arc: Shape {
    var startAngle: Angle
    var endAngle: Angle
    func path(in rect: CGRect) -> Path {
        var path = Path()
        path.addLines([CGPoint(x:rect.midX, y:rect.midY)])
        path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.width / 2, startAngle: startAngle, endAngle: endAngle, clockwise: false)
        //path.addLine(to: CGPoint(x:rect.midX, y:rect.midY))
        return path
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView().environmentObject(PublicManager())
    }
}

NumberRouletteApp.swift

//
//  NumberRouletteApp.swift
//  NumberRoulette
//
//  Created by akira ohmachi on 2021/04/06.
//

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 NumberRouletteApp: App {
    // SwiftUI AppライフサイクルにAppDelegateクラスを注入する
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
        WindowGroup {
            ContentView().environmentObject(PublicManager())
        }
    }
}

PublicManager.swift

//
//  PublicManager.swift
//  NumberRoulette
//
//  Created by akira ohmachi on 2021/04/06.
//

import SwiftUI
import GoogleMobileAds

class PublicManager: ObservableObject {
    
    @Published var isSetting: Bool = false

    @AppStorage("numberMin") var numberMin: Int = 0
    @AppStorage("numberMax") var numberMax: Int = 25
    @AppStorage("numberReverse") var numberReverse: Bool = false
    @AppStorage("numberRandom") var numberRandom: Bool = false
    @AppStorage("shortTime") var shortTime: Bool = false
    
    var tmpNumberMin: String = "0"
    var tmpNumberMax: String = "25"
    var tmpNumberReverse: Bool = false
    var tmpNumberRandom: Bool = false
    var tmpShortTime: Bool = false

    //--------------------------------------------------
    //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
//  NumberRoulette
//
//  Created by akira ohmachi on 2021/04/06.
//

import SwiftUI

struct SettingView: View {
    @EnvironmentObject var pub: PublicManager
    
    var body: some View {
        VStack {
            HStack {
                Button(action: {
                    pub.isSetting = false
                }) {
                    HStack {
                        Image(systemName: "arrow.backward")
                        Text("cancel")
                    }
                }
                Spacer()
                Button(action: {
                    self.pub.numberMin = self.adjustStrToNum(str: self.pub.tmpNumberMin)
                    self.pub.numberMax = self.adjustStrToNum(str: self.pub.tmpNumberMax)
                    self.pub.numberReverse = self.pub.tmpNumberReverse
                    self.pub.numberRandom = self.pub.tmpNumberRandom
                    self.pub.shortTime = self.pub.tmpShortTime
                    pub.isSetting = false
                }) {
                    HStack {
                        Text("apply")
                        Image(systemName: "checkmark.circle")
                    }
                }
            }
            .padding(20)
        }
        GeometryReader { bodyView in
            ScrollView {
                VStack {
                    VStack {
                        self.border()
                        HStack {
                            Text("numberMin")
                                .font(.subheadline)
                            Spacer()
                            TextField("", text: Binding(
                                get: {self.pub.tmpNumberMin},
                                set: {self.pub.tmpNumberMin = $0.filter{"0123456789".contains($0)}})
                            )
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .keyboardType(.numberPad)
                            .frame(width:bodyView.size.width / 2)
                        }.padding(.horizontal)
                        HStack {
                            Text("numberMin1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.horizontal)
                        self.border()
                        HStack {
                            Text("numberMax")
                                .font(.subheadline)
                            Spacer()
                            TextField("", text: Binding(
                                get: {self.pub.tmpNumberMax},
                                set: {self.pub.tmpNumberMax = $0.filter{"0123456789".contains($0)}})
                            )
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .keyboardType(.numberPad)
                            .frame(width:bodyView.size.width / 2)
                        }.padding(.horizontal)
                        HStack {
                            Text("numberMax1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.horizontal)
                    }
                    VStack {
                        self.border()
                        Toggle(isOn: self.$pub.tmpNumberReverse) {
                            Text("numberReverse")
                                .font(.subheadline)
                        }.padding(.horizontal)
                        HStack {
                            Text("numberReverse1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.horizontal)
                        self.border()
                        Toggle(isOn: self.$pub.tmpNumberRandom) {
                            Text("numberRandom")
                                .font(.subheadline)
                        }.padding(.horizontal)
                        HStack {
                            Text("numberRandom1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.horizontal)
                        self.border()
                        Toggle(isOn: self.$pub.tmpShortTime) {
                            Text("shortTime")
                                .font(.subheadline)
                        }.padding(.horizontal)
                        HStack {
                            Text("shortTime1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.horizontal)
                    }
                    self.border()
                    VStack {
                        HStack {
                            Text("usage")
                                .font(.subheadline)
                            Spacer()
                        }
                        HStack {
                            Text("usage1")
                                .font(.footnote)
                            Spacer()
                        }.padding(.vertical,5)
                    }.padding()
                }
            }
        }
        //.navigationBarTitle("Setting",displayMode: .automatic)
        //.navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onTapGesture {     //背景タップでキーボードを閉じる
            UIApplication.shared.closeKeyboard()
        }
    }
    
    private func adjustStrToNum(str: String) -> Int {
        let num: Int = NumberFormatter().number(from: "0" + str) as! Int
        return num
    }
    
    private func border() -> some View {
        var body: some View {
            HStack {
                Rectangle().fill(Color.init(red: 0.9, green: 0.9, blue: 0.9)).frame(height: 1)
            }
            .padding(.horizontal)
            .padding(.vertical,10)
        }
        return body
    }

}

extension UIApplication {
    func closeKeyboard() {  //キーボードを閉じる
        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}

struct SettingView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            SettingView().environmentObject(PublicManager())
        }
    }
}
このページでお気付きの点がございましたら
ご連絡いただけますと幸いです。
Eメール(任意)
送信内容
 

■ 便利ウェブサイト