lecture 2a: basics of ios development (using swift with
TRANSCRIPT
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 🎬
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 🎬
Project A
Noah Jacobson Kabir Jolly Rachel Naidich Amrita Kaur
Project B
Henry MellsopColton Swingle Collin Schlager
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%)
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%)
© 2016 Stanford Byers Center for Biodesign
https://cs342.stanford.edu
let’s go through some basics!
refer to this guide
© 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
© 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
© 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"
© 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."
© 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"
© 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"
© 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
© 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"
© 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!
© 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
© 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 }
© 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
© 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
© 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"
The predecessor of SwiftUI
The modern, declarative way to design user interfaces for iOS
“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
https://stackoverflow.com/questions/1784664/what-is-the-difference-between-declarative-and-imperative-paradi
gm-in-programmin
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/
Views and Controls
Views and Controls
Views and Controls
��
Layout and Presentation
Layout and Presentation
https://learnxinyminutes.com/docs/swift/
https://goshdarnswiftui.com
https://developer.apple.com/tutorials/swiftui/
Let’s review some basic git commands…
Source: https://education.github.com/git-cheat-sheet-education.pdf
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
☕
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.
Project A
Noah Jacobson Kabir Jolly Rachel Naidich Amrita Kaur
Project B
Henry MellsopColton Swingle Collin Schlager
© 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
49
Thank you!
Stanford Byers Center for Biodesign318 Campus Drive, E100Stanford, CA 94305