How to Build a Simple Dog Walking Timer App
Your dog stares at you. It's 6 PM. You know you promised a walk, but how long has it been? Two hours? 20 minutes?
A dog walking timer app is simple, useful, and a perfect first project to learn iOS development. In this tutorial, we'll build a functional timer app in Swift using SwiftUI. No previous experience required—just curiosity and a Mac with Xcode.
What We're Building
A dog walking timer app that:
- Starts a timer when you begin your walk
- Displays elapsed time in a readable format
- Lets you pause and resume
- Tracks your longest walk
- Shows time in minutes and seconds
By the end, you'll have a working iOS app you can actually use with your dog.
Prerequisites
- Mac with Xcode (free on the App Store)
- Basic Swift understanding (or willingness to learn)
- 30 minutes to follow along
Step 1: Create a New SwiftUI Project
- Open Xcode
- Select File → New → Project
- Choose iOS → App
- Set Product Name to
DogWalkTimer - Select SwiftUI for the interface
- Click Create
Step 2: Set Up the Data Model
Create a new file called WalkTimer.swift:
import Foundation
class WalkTimer: ObservableObject {
@Published var elapsedTime: TimeInterval = 0
@Published var isRunning = false
@Published var longestWalk: TimeInterval = 0
private var timer: Timer?
func start() {
guard !isRunning else { return }
isRunning = true
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.elapsedTime += 1
}
}
func pause() {
isRunning = false
timer?.invalidate()
}
func stop() {
pause()
if elapsedTime > longestWalk {
longestWalk = elapsedTime
}
elapsedTime = 0
}
func formattedTime(_ seconds: TimeInterval) -> String {
let minutes = Int(seconds) / 60
let secs = Int(seconds) % 60
return String(format: "%02d:%02d", minutes, secs)
}
}
Step 3: Build the UI
Replace the contents of ContentView.swift:
import SwiftUI
struct ContentView: View {
@StateObject var walkTimer = WalkTimer()
var body: some View {
ZStack {
LinearGradient(
gradient: Gradient(colors: [.blue, .cyan]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
.ignoresSafeArea()
VStack(spacing: 30) {
Text("Dog Walk Timer")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.white)
VStack(spacing: 20) {
Text(walkTimer.formattedTime(walkTimer.elapsedTime))
.font(.system(size: 72, weight: .bold, design: .monospaced))
.foregroundColor(.white)
HStack(spacing: 20) {
Button(action: {
walkTimer.start()
}) {
Text("Start")
.frame(maxWidth: .infinity)
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(10)
}
.disabled(walkTimer.isRunning)
Button(action: {
walkTimer.pause()
}) {
Text("Pause")
.frame(maxWidth: .infinity)
.padding()
.background(Color.orange)
.foregroundColor(.white)
.cornerRadius(10)
}
.disabled(!walkTimer.isRunning)
}
Button(action: {
walkTimer.stop()
}) {
Text("Stop & Save")
.frame(maxWidth: .infinity)
.padding()
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(10)
}
.disabled(!walkTimer.isRunning && walkTimer.elapsedTime == 0)
}
.padding()
.background(Color.white.opacity(0.2))
.cornerRadius(15)
VStack(spacing: 10) {
Text("Longest Walk")
.font(.headline)
.foregroundColor(.white)
Text(walkTimer.formattedTime(walkTimer.longestWalk))
.font(.system(size: 48, weight: .semibold, design: .monospaced))
.foregroundColor(.yellow)
}
.padding()
.background(Color.white.opacity(0.1))
.cornerRadius(15)
Spacer()
}
.padding(20)
}
}
}
Step 4: Test the App
- Press Cmd + R to run the app in the simulator
- Click Start → timer counts up
- Click Pause → timer stops
- Click Start again → timer resumes
- Click Stop & Save → time resets, updates longest walk
Accessories to Enhance Your Dog Walks
Need gear to make dog walks easier? Consider these:
You now have a working iOS app.
Top comments (0)