Mobile App Development 2021W Lecture 3

From Soma-notes
Revision as of 00:42, 20 January 2021 by Soma (talk | contribs) (→‎Code)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Video

Video from the lecture given on January 18, 2020 is now available.

Notes

Lecture 3
------------

Tutorial 1
command line Swift
Swift language concepts
 - class vs struct
 - types
 
Most programming languages have ways to represent collections of data
We normally call these objects nowadays, but objects have a few other properties
abstract data types are what objects are based on

normally we want to associate code with data
 - variabes and functions to go with it

an abstract data type is this combination

objects are abstract data types + inheritance

roughly in swift, struct's are abstract data types, class's are objects
 - no inheritance with struct's

but there's one other big difference
 - classes are reference types
 - struct's are value types



Certificates
  - when you install an application, how do you know who created it?
    - is the code coming from a trusted source?
 - code signing certificates are how we make sure that code is legit
   - could still be malicious, but at least we'll know who to blame

Every developer should have their own certificate that they use to sign their code

when you install a program, the operating system checks the signature on the code
to see if it is valid and associated with a trusted certificate
 - if it isn't, it doesn't allow the code to run (or it puts up big warnings that can
   be overridden)
 - "untrusted publisher" messages

Underlying certificates is public key cryptography
 - a certificate is just a public key with associated metadata (i.e., someone's name
   email address, etc)

Basic idea of public key crypto signatures
 - create a sig with private key
 - associated public key can verify signature
    - if it is verified, you know the signed data has not been tampered with
       and it was signed by someone with the private key

Certificates are the basis of app stores
 - devices will only run code signed by trusted certificates
 - the app store controls what is trusted

Code

lec03-cmd.zip

lec03-cmd/main.swift

//
//  main.swift
//  lec03-cmd
//
//  Created by Anil Somayaji on 2021-01-18.
//

struct s {
    var v = 0
}

class c {
    var v = 0
}

class car {
    private var colour: String = "Red"
    
    func getColour () -> String {
        return colour
    }
    
    func setColour (c: String) {
        colour = c
    }
    
    init (c: String) {
        colour = c
    }
}

var saturn: car = car(c: "Red")
saturn.setColour(c: "Blue")
let newColour = saturn.getColour()
print("Saturn colour is \(newColour).")

var s1 = s()
var s2 = s1

var c1 = c()
var c2 = c1

c2.v = 5
s2.v = 5

print("c1.v = \(c1.v)")
print("s1.v = \(s1.v)")