diff --git a/DebuggingAndProfiling/ContentView.swift b/DebuggingAndProfiling/ContentView.swift index f931a6d..0d371e0 100644 --- a/DebuggingAndProfiling/ContentView.swift +++ b/DebuggingAndProfiling/ContentView.swift @@ -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") @@ -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() } diff --git a/DebuggingAndProfiling/DebugThisCode.swift b/DebuggingAndProfiling/DebugThisCode.swift index 647fc57..465b49e 100644 --- a/DebuggingAndProfiling/DebugThisCode.swift +++ b/DebuggingAndProfiling/DebugThisCode.swift @@ -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") @@ -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")