ContentView - marleysudbury/swiftui-calculator GitHub Wiki

This file contains the single view of the app that the user directly accesses. This view is made up of the other views contained within the app.

This file contents can be broken down like so:

  • The ContentView structure
    • buttonSize: CGFloat = 75.0 a constant property used to specify the size of the CalcButtons
    • spacing: CGFloat = 10.0 a constant property used to specify the space between CalcButtons
    • @EnvironmentObject var appData: DataStoreXD which is our global data store
    • var body: some View which is the ContentView screen itself
      • VStack with the background colour bg
        • CalcScreen which has appData.value passed as a parameter, and horizontal padding.
        • Keyboard which has buttonSize and spacing passed as parameters, which are class properties of this screen.
  • The DataStoreXD class, which can be accessed from any view
    • @Published var value: String stores the value on the screen
    • @Published var decimal: Bool stores if the value has a decimal part
    • @Published var cache: String stores a previous value
    • @Published var ac: Bool AC button says 'AC' if true, 'C' if false
    • @Published var active: Dictionary<String, Bool> for each operation button, is it active?
    • init() initialises the object
  • The preview structure
    • An instance of ContentView()