lecture 2a: basics of ios development (using swift with

51
CS342/MED253 Building for Digital Health Lecture 2A: Basics of iOS Development (using Swift with xcode) and Git Santiago Gutierrez Oliver Aalami Mike Hittle Varun Shenoy Aish Venkatramani Winter 2020 https://cs342.stanford.edu cardinalkit.slack.com Welcome! Don’t forget to record lecture

Upload: others

Post on 02-Jul-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 2A: Basics of iOS Development (using Swift with

CS342/MED253 Building for Digital HealthLecture 2A: Basics of iOS Development (using Swift with xcode) and Git

Santiago GutierrezOliver Aalami

Mike HittleVarun Shenoy

Aish Venkatramani

Winter 2020

https://cs342.stanford.edu

cardinalkit.slack.com

Welcome!

Don’t forget to record lecture 🎬

Page 2: Lecture 2A: Basics of iOS Development (using Swift with

Overview for today- Announcements

- Swift Basics

- What is SwiftUI ?

- Coffee Time (breakout in groups of 3 for socializing)

- Live-code demo.

https://cs342.stanford.edu

cs342-aut1920.slack.com

Don’t forget to record lecture 🎬

Page 3: Lecture 2A: Basics of iOS Development (using Swift with

Project A

Noah Jacobson Kabir Jolly Rachel Naidich Amrita Kaur

Project B

Henry MellsopColton Swingle Collin Schlager

Page 4: Lecture 2A: Basics of iOS Development (using Swift with

Due Jan 26thFor this assignment, your goal is to set up Xcode, create a basic SwiftUI app, and submit via GitHub.

You will be graded for completion of the following:

1. Install Xcode and Git on your machine.2. Complete Chapter 1 of the official SwiftUI

tutorial.3. If you are new to Git, complete the following

tutorial.

4. Create a SwiftUI iOS app with a basic information

card about yourself (85%)5. Submit your code via a GitHub pull request

(15%)

Page 5: Lecture 2A: Basics of iOS Development (using Swift with

Due Jan 26thFor this assignment, your goal is to set up Xcode, create a basic SwiftUI app, and submit via GitHub.

You will be graded for completion of the following:

1. Install Xcode and Git on your machine.2. Complete Chapter 1 of the official SwiftUI

tutorial.3. If you are new to Git, complete the following

tutorial.

4. Create a SwiftUI iOS app with a basic information

card about yourself (85%)5. Submit your code via a GitHub pull request

(15%)

Page 6: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

let’s go through some basics!

refer to this guide

Page 7: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Constants ( let ) and variables ( var )

let maximumNumberOfLoginAttempts = 10

var currentLoginAttempt = 0

^ cannot be changed once set

var x = 0.0, y = 0.0, z = 0.0

v type inference

Page 8: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Type Annotations

let maximumNumberOfLoginAttempts: Int = 10

var welcomeMessage: String = “Hello”

Int, Float, Double, Bool, String

Page 9: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Comments & Print statements

1 // This is a comment. 2 3 /* This is also a comment 4 but is written over multiple lines. //

1 let languageName = "Swift" 2 3 print(languageName) 4 // Prints "Swift" 5 6 print("The current value of languageName is \(languageName)") 7 // Prints "The current value of languageName is Swift"

Page 10: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Booleans and if-statements

let orangesAreOrange = true let turnipsAreDelicious = false

1 if turnipsAreDelicious { 2 print("Mmm, tasty turnips!") 3 } else { 4 print("Eww, turnips are horrible.") 5 } 6 // Prints "Eww, turnips are horrible."

Page 11: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Optionals

1 var convertedNumber: Int? = 404

2 //convertedNumber contains an actual Int value of 404

3 convertedNumber = nil

4 //convertedNumber now contains no value

1 var possibleNumber = "123"

2 var convertedNumber = Int(possibleNumber)

3 // convertedNumber is inferred to be of type "Int?", or "optional Int"

Page 12: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Optionals

1 if convertedNumber /= nil {

2 print("convertedNumber has an integer value of \(convertedNumber!).")

3 }

4 // Prints "convertedNumber has an integer value of 123."

force unwrap (can crash)

1 if let convertedNumber = Int(possibleNumber) {

2 print("The string \"\(possibleNumber)\" has an integer value of \(convertedNumber)")

3 } else {

4 print("The string \"\(possibleNumber)\" could not be converted to an integer")

5 }

6 // Prints "The string "123" has an integer value of 123"

Page 13: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Arrays

1 var shoppingList = ["Eggs", "Milk"] 2 print("The shopping list contains \(shoppingList.count) items.") 3 4 shoppingList.append("Flour") 5 shoppingList[0] // Eggs

Page 14: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Dictionaries

1 var airports: [String: String] = ["YYZ": "Toronto Pearson", "DUB": "Dublin"] 2 var airports = ["YYZ": "Toronto Pearson", "DUB": "Dublin"] 3 4 print("The airports dictionary contains \(airports.count) items.") 5 // Prints "The airports dictionary contains 2 items." 6 7 airports["LHR"] = "London" 8 // the airports dictionary now contains 3 items 9 10 airports["LHR"] = "London Heathrow"11 // the value for "LHR" has been changed to "London Heathrow"

Page 15: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

For-In loops

1 let names = ["Anna", "Alex", "Brian", "Jack"]

2 for name in names {

3 print("Hello, \(name)!")

4 }

5 // Hello, Anna!

6 // Hello, Alex!

7 // Hello, Brian!

8 // Hello, Jack!

Page 16: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

For-In loops

1 let numberOfLegs = ["spider": 8, "ant": 6, "cat": 4]

2 for (animalName, legCount) in numberOfLegs {

3 print("\(animalName)s have \(legCount) legs")

4 }

5 // cats have 4 legs

6 // ants have 6 legs

7 // spiders have 8 legs

Page 17: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Structures and Classes

1 struct Resolution { 2 var width = 0 3 var height = 0 4 } 5 class VideoMode { 6 var resolution = Resolution() 7 var interlaced = false 8 var frameRate = 0.0 9 var name: String?10 }

Page 18: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Structures and Classes

1 let someResolution = Resolution() 2 let someVideoMode = VideoMode() 3 4 print("The width of someResolution is \(someResolution.width)") 5 // Prints "The width of someResolution is 0" 6 7 print("The width of someVideoMode is \(someVideoMode.resolution.width)") 8 // Prints "The width of someVideoMode is 0" 9 10 someVideoMode.resolution.width = 1280

Page 19: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Functions

1 func greet(person: String) { 2 print("Hello, \(person)!") 3 } 4 5 func greet(person: String) /> String { 6 let greeting = "Hello, " + person + "!" 7 return greeting 8 } 9 10 func greet(person: String, alreadyGreeted: Bool) /> String {11 //.12 }

Int, Float, Double, Bool, String

Page 20: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Enums

1 enum CompassPoint { 2 case north 3 case south 4 case east 5 case west 6 }

1 var directionToHead = CompassPoint.south 2 9 switch directionToHead { 3 10 case .north: 4 print("Lots of planets have a north") 5 12 case .south: 6 print("Watch out for penguins") 7 14 case .east: 8 print("Where the sun rises") 9 16 case .west:10 print("Where the skies are blue")11 18 }12 19 // Prints "Watch out for penguins"

Page 21: Lecture 2A: Basics of iOS Development (using Swift with
Page 22: Lecture 2A: Basics of iOS Development (using Swift with

The predecessor of SwiftUI

Page 23: Lecture 2A: Basics of iOS Development (using Swift with
Page 24: Lecture 2A: Basics of iOS Development (using Swift with
Page 25: Lecture 2A: Basics of iOS Development (using Swift with

The modern, declarative way to design user interfaces for iOS

Page 26: Lecture 2A: Basics of iOS Development (using Swift with
Page 27: Lecture 2A: Basics of iOS Development (using Swift with
Page 28: Lecture 2A: Basics of iOS Development (using Swift with
Page 29: Lecture 2A: Basics of iOS Development (using Swift with

“Creators need an immediate connection to what they create. And what I mean by that is when you’re making something, if you make a change, or you make a decision, you need to see the effect of that immediately.”

- Bret Victor

Page 30: Lecture 2A: Basics of iOS Development (using Swift with

https://stackoverflow.com/questions/1784664/what-is-the-difference-between-declarative-and-imperative-paradi

gm-in-programmin

Page 31: Lecture 2A: Basics of iOS Development (using Swift with
Page 32: Lecture 2A: Basics of iOS Development (using Swift with

How can you use SwiftUI to supercharge your iOS workflow?

Goal: be able to write basic SwiftUI and fluently read SwiftUI

codebases

Sources: goshdarnswiftui.com, developer.apple.com/documentation/swiftui/

Page 33: Lecture 2A: Basics of iOS Development (using Swift with

Views and Controls

Page 34: Lecture 2A: Basics of iOS Development (using Swift with

Views and Controls

Page 35: Lecture 2A: Basics of iOS Development (using Swift with

Views and Controls

��

Page 36: Lecture 2A: Basics of iOS Development (using Swift with

Layout and Presentation

Page 37: Lecture 2A: Basics of iOS Development (using Swift with

Layout and Presentation

Page 38: Lecture 2A: Basics of iOS Development (using Swift with

https://learnxinyminutes.com/docs/swift/

https://goshdarnswiftui.com

https://developer.apple.com/tutorials/swiftui/

Page 39: Lecture 2A: Basics of iOS Development (using Swift with

Let’s review some basic git commands…

Source: https://education.github.com/git-cheat-sheet-education.pdf

Page 40: Lecture 2A: Basics of iOS Development (using Swift with
Page 41: Lecture 2A: Basics of iOS Development (using Swift with
Page 42: Lecture 2A: Basics of iOS Development (using Swift with
Page 43: Lecture 2A: Basics of iOS Development (using Swift with
Page 44: Lecture 2A: Basics of iOS Development (using Swift with

Coffee Time

● 5 - 10 min● Opportunity to mingle / take a break ● Ice breaker question for the day:

How would you build this?

https://cs342.stanford.edu

cs342-aut1920.slack.com

Page 45: Lecture 2A: Basics of iOS Development (using Swift with
Page 46: Lecture 2A: Basics of iOS Development (using Swift with

Next Class

Assignments#2: Assignment #2: ResearchKit + Firebase

ResearchKit is an open source framework introduced by Apple that allows researchers and developers to create

powerful apps for medical research.

Page 47: Lecture 2A: Basics of iOS Development (using Swift with

Project A

Noah Jacobson Kabir Jolly Rachel Naidich Amrita Kaur

Project B

Henry MellsopColton Swingle Collin Schlager

Page 48: Lecture 2A: Basics of iOS Development (using Swift with

© 2016 Stanford Byers Center for Biodesign

https://cs342.stanford.edu

Attendance Check ✋🏼● Use the following link to mark your attendance for today:

http://bit.ly/cs342-attendance-check

Page 49: Lecture 2A: Basics of iOS Development (using Swift with

49

Thank you!

Page 50: Lecture 2A: Basics of iOS Development (using Swift with

Stanford Byers Center for Biodesign318 Campus Drive, E100Stanford, CA 94305

Page 51: Lecture 2A: Basics of iOS Development (using Swift with