Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions DebuggingAndProfiling/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
// 2 - The app redrew its views 7 times in the 30 sec OccassionalUpdate was in the foreground and 2,730 times while stress test was in the foreground

// 3 - In the OccationalUpdate, starting took 19.82s in the 30sec it was in the foreground. In stressTest, it took 5.96 sec. So while the views were drawn more times during the stress test, those were updating faster so it didn't use as much CPU.
OccassionalUpdate()
.tabItem {
Image(systemName: "smiley")
Expand All @@ -25,6 +28,13 @@ struct ContentView: View {
Image(systemName: "ant")
Text("DebugThisCode")
}

// The algorithm for converting fahrenheit to celsius was incorrect, and the resulting variable declaration needed to be changed from var to let.

//ORIGINAL - var cel = (fah + 32) * 5 / 9
//CORRECT - let cel = (fah - 32) * 5 / 9
//ORIGINAL - var fah = (cel * 5 / 9 ) + 32
//CORRECT - let fah = (cel * 9 / 5) + 32
}
.padding()
}
Expand Down
6 changes: 4 additions & 2 deletions DebuggingAndProfiling/DebugThisCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct DebugThisCode: View {
print("Fah changed to \(fahrenheitTemp)")
if let fah = Double(fahrenheitTemp) {
print("Value is \(fah)")
var cel = (fah + 32) * 5 / 9
//var cel = (fah + 32) * 5 / 9
let cel = (fah - 32) * 5 / 9
celsiusTemp = String(cel)
} else {
print("Not a valid number")
Expand All @@ -42,7 +43,8 @@ struct DebugThisCode: View {
TextField("Temperature in Celsius", text: $celsiusTemp)
Button(action: {
if let cel = Double(celsiusTemp) {
var fah = (cel * 5 / 9 ) + 32
//var fah = (cel * 5 / 9 ) + 32
let fah = (cel * 9 / 5) + 32
fahrenheitTemp = String(fah)
} else {
print("Not a valid number")
Expand Down