Mobile App Development 2021W Lecture 4: Difference between revisions

From Soma-notes
Created page with "==Video== Video from the lecture given on January 20, 2021 [https://homeostasis.scs.carleton.ca/~soma/mad-2021w/lectures/comp1601-2021w-lec04-20210120.m4v is now available]."
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


Video from the lecture given on January 20, 2021 [https://homeostasis.scs.carleton.ca/~soma/mad-2021w/lectures/comp1601-2021w-lec04-20210120.m4v is now available].
Video from the lecture given on January 20, 2021 [https://homeostasis.scs.carleton.ca/~soma/mad-2021w/lectures/comp1601-2021w-lec04-20210120.m4v is now available].
==Notes==
Historical articles referenced in class:
* [https://www.dougengelbart.org/content/view/209/448/ The Mother of All Demos]
* [https://en.wikipedia.org/wiki/Xerox_Alto Xerox Alto]
* [https://en.wikipedia.org/wiki/Apple_Lisa Apple Lisa]
* [https://en.wikipedia.org/wiki/ResEdit ResEdit]
* [http://www.kevra.org/TheBestOfNext/page570/page571/page571.html NeXT development tools]
<pre>
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
</pre>
==Code==
[https://homeostasis.scs.carleton.ca/~soma/mad-2021w/code/tut01-test.zip tut01-test.zip]
===tut01-test/Shared/ContentView.swift===
<syntaxhighlight lang="swift" line>
//
//  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()
    }
}
</syntaxhighlight>

Latest revision as of 21:08, 20 January 2021

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()
    }
}