Mobile App Development 2021W Lecture 4

From Soma-notes
Jump to navigation Jump to search

Video

Video from the lecture given on January 20, 2021 is now available.

Notes

Historical articles referenced in class:


Lecture 4
------------

* nested views
* UIkit
* Apple-centered history of GUIs
  - mother of all demos (Englebart, 1968)
  - Xerox Alto
  - Lisa
  - Macintosh
  - NeXT
  - MacOS X
  - iPhone


Why not just use HTML/CSS everywhere, instead of SwiftUI?
 - because then you need an entire web renderer to create the interface!
 - web rendering engines are BEASTS
   - only 3 left
      Webkit (Apple)
      Blink (Google, fork of Webkit)
      Gecko (Mozilla)

Microsoft had Trident, but they gave up and adopted Blink for Edge

UIkit is for iOS, AppKit is for MacOS
 - storyboard is the way you make these interfaces

SwiftUI is for both MacOS and iOS


SwiftUI is really a domain-specific language for building interfaces,
built using Swift
 - some rules of regular swift apply, but many don't
 - really need to switch modes when doing SwiftUI
 - only use SwiftUI components in Views, not elsewhere

Code

tut01-test.zip

tut01-test/Shared/ContentView.swift

//
//  ContentView.swift
//  Shared
//
//  Created by Anil Somayaji on 2021-01-19.
//

import SwiftUI

struct ContentView: View {
    @State private var Fs = ""
    
    var body: some View {
        VStack{
            Text("Temperature Converter")
                .font(.title)
                .fontWeight(.bold)
                .padding()
            
            Spacer()
            TextField("Enter Farenheit", text: $Fs)
            SubView(Fs: $Fs)
            Spacer()
        }
    }
}

struct SubView: View {
    @Binding var Fs: String
    var body: some View {
        if let F = Double(Fs) {
            let C = (F - 32.0) * (5/9)
            let Cs = String(format: "%0.2f", C)
            
            Text("\(Fs) is \(Cs) Celsius")
            
            let K = C + 273.15
            let Ks = String(format: "%0.2f", K)
            Text("\(Fs) is \(Ks) Kelvin")
        } else {
            Text("Enter a number please.")
        }
    }
}

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