Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging and Profiling using Instruments - Tori #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Ready to go!
  • Loading branch information
Tori-Lew committed Oct 11, 2023
commit a233bb126926278fc795ae293c5d7bd6cb02c585
140 changes: 140 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,xcode,swift,swiftpackagemanager
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,xcode,swift,swiftpackagemanager

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### SwiftPackageManager ###
Packages
xcuserdata
*.xcodeproj


### Xcode ###

## Xcode 8 and earlier

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/macos,xcode,swift,swiftpackagemanager
16 changes: 16 additions & 0 deletions DebuggingAndProfiling.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
E427DB7C2ACCFAE1000C6F53 /* DebuggingAndProfilingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB7B2ACCFAE1000C6F53 /* DebuggingAndProfilingTests.swift */; };
E427DB862ACCFAE1000C6F53 /* DebuggingAndProfilingUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB852ACCFAE1000C6F53 /* DebuggingAndProfilingUITests.swift */; };
E427DB882ACCFAE1000C6F53 /* DebuggingAndProfilingUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB872ACCFAE1000C6F53 /* DebuggingAndProfilingUITestsLaunchTests.swift */; };
E427DB952ACD02BB000C6F53 /* StressTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB942ACD02BB000C6F53 /* StressTest.swift */; };
E427DB972ACD02CE000C6F53 /* OccassionalUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB962ACD02CE000C6F53 /* OccassionalUpdate.swift */; };
E427DB992ACD14F0000C6F53 /* DebugThisCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = E427DB982ACD14F0000C6F53 /* DebugThisCode.swift */; };
E427DB9B2ACD296C000C6F53 /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = E427DB9A2ACD296C000C6F53 /* .gitignore */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -44,6 +48,10 @@
E427DB812ACCFAE1000C6F53 /* DebuggingAndProfilingUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DebuggingAndProfilingUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
E427DB852ACCFAE1000C6F53 /* DebuggingAndProfilingUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggingAndProfilingUITests.swift; sourceTree = "<group>"; };
E427DB872ACCFAE1000C6F53 /* DebuggingAndProfilingUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebuggingAndProfilingUITestsLaunchTests.swift; sourceTree = "<group>"; };
E427DB942ACD02BB000C6F53 /* StressTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StressTest.swift; sourceTree = "<group>"; };
E427DB962ACD02CE000C6F53 /* OccassionalUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OccassionalUpdate.swift; sourceTree = "<group>"; };
E427DB982ACD14F0000C6F53 /* DebugThisCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugThisCode.swift; sourceTree = "<group>"; };
E427DB9A2ACD296C000C6F53 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -74,6 +82,7 @@
E427DB5E2ACCFADD000C6F53 = {
isa = PBXGroup;
children = (
E427DB9A2ACD296C000C6F53 /* .gitignore */,
E427DB692ACCFADD000C6F53 /* DebuggingAndProfiling */,
E427DB7A2ACCFAE1000C6F53 /* DebuggingAndProfilingTests */,
E427DB842ACCFAE1000C6F53 /* DebuggingAndProfilingUITests */,
Expand All @@ -96,6 +105,9 @@
children = (
E427DB6A2ACCFADD000C6F53 /* DebuggingAndProfilingApp.swift */,
E427DB6C2ACCFADD000C6F53 /* ContentView.swift */,
E427DB942ACD02BB000C6F53 /* StressTest.swift */,
E427DB962ACD02CE000C6F53 /* OccassionalUpdate.swift */,
E427DB982ACD14F0000C6F53 /* DebugThisCode.swift */,
E427DB6E2ACCFAE0000C6F53 /* Assets.xcassets */,
E427DB702ACCFAE0000C6F53 /* Preview Content */,
);
Expand Down Expand Up @@ -232,6 +244,7 @@
buildActionMask = 2147483647;
files = (
E427DB722ACCFAE0000C6F53 /* Preview Assets.xcassets in Resources */,
E427DB9B2ACD296C000C6F53 /* .gitignore in Resources */,
E427DB6F2ACCFAE0000C6F53 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -257,7 +270,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E427DB972ACD02CE000C6F53 /* OccassionalUpdate.swift in Sources */,
E427DB6D2ACCFADD000C6F53 /* ContentView.swift in Sources */,
E427DB952ACD02BB000C6F53 /* StressTest.swift in Sources */,
E427DB992ACD14F0000C6F53 /* DebugThisCode.swift in Sources */,
E427DB6B2ACCFADD000C6F53 /* DebuggingAndProfilingApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
21 changes: 16 additions & 5 deletions DebuggingAndProfiling/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ import SwiftUI

struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
TabView {
OccassionalUpdate()
.tabItem {
Image(systemName: "smiley")
Text("OccassionalUpdate")
}
StressTest()
.tabItem {
Image(systemName: "exclamationmark.arrow.triangle.2.circlepath")
Text("StressTest")
}
DebugThisCode()
.tabItem {
Image(systemName: "ant")
Text("DebugThisCode")
}
}
.padding()
}
Expand Down
70 changes: 70 additions & 0 deletions DebuggingAndProfiling/DebugThisCode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// DebugThisCode.swift
// DebuggingAndProfiling
//
// Created by Mike Panitz on 10/3/23.
//

import SwiftUI

struct DebugThisCode: View {
@State var fahrenheitTemp = ""
@State var celsiusTemp = ""
var body: some View {
VStack {
Text("Fahrenheit to Celsius")
.font(.largeTitle)
Spacer()
VStack {
Text("Fahrenheit:")
TextField("Temperature in Fahrenheit", text: $fahrenheitTemp)
Button(action: {
print("Fah changed to \(fahrenheitTemp)")
if let fah = Double(fahrenheitTemp) {
print("Value is \(fah)")
var cel = (fah + 32) * 5 / 9
celsiusTemp = String(cel)
} else {
print("Not a valid number")
}
}) {
Text("Convert to Celsius")
.font(.headline)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
}.padding(.bottom)

VStack {
Text("Celsius:")
TextField("Temperature in Celsius", text: $celsiusTemp)
Button(action: {
if let cel = Double(celsiusTemp) {
var fah = (cel * 5 / 9 ) + 32
fahrenheitTemp = String(fah)
} else {
print("Not a valid number")
}
}) {
Text("Convert to Fahrenheit")
.font(.headline)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}

}.padding(.top)
Spacer()
}
.padding()
}
}

struct DebugThisCode_Previews: PreviewProvider {
static var previews: some View {
DebugThisCode()
}
}
51 changes: 51 additions & 0 deletions DebuggingAndProfiling/OccassionalUpdate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// OccassionalUpdate.swift
// DebuggingAndProfiling
//
// Created by Mike Panitz on 10/3/23.
//

import SwiftUI

func TheSlowFunction() {
var changeThisVar = 0
for _ in 0 ... 100000 {
for j in 0 ... 100000 {
changeThisVar = j
print(j)
}
}
}

func CallTheSlowFunction() {
print("About to call the slow function")
TheSlowFunction()
print("Done with the slow function")
}

struct OccassionalUpdate: View {
var body: some View {
VStack {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
Button(action: {
// Code to be executed when the button is tapped
print("Button tapped! Message printed to debug console.")
CallTheSlowFunction()
}) {
Text("Tap Me!")
.font(.headline)
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
}
}
}
}

struct OccassionalUpdate_Previews: PreviewProvider {
static var previews: some View {
OccassionalUpdate()
}
}

43 changes: 43 additions & 0 deletions DebuggingAndProfiling/StressTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

//
// ContentView.swift
// DebuggingAndProfiling
//
// Created by Mike Panitz on 10/3/23.
//

import SwiftUI

class FrequentUpdater: ObservableObject {
var timer: Timer?

init() {
timer = Timer.scheduledTimer(
withTimeInterval: 0.01,
repeats: true
) { _ in
self.objectWillChange.send()
}
}
}

struct StressTest: View {
@StateObject private var updater = FrequentUpdater()
@State private var tapCount = 0

var body: some View {
VStack {
Text("\(UUID().uuidString)")

Button("Tap count: \(tapCount)") {
tapCount += 1
}
}
}
}

struct StressTest_Previews: PreviewProvider {
static var previews: some View {
StressTest()
}
}