How to Build a Morse Code App in SwiftUI
A Morse Code app lets users translate plain text into dot-dash sequences and hear them played back in real time — perfect for students, radio enthusiasts, and anyone curious about this classic communication system.
Prerequisites
- Xcode 16 or later installed on a Mac running macOS Sequoia+
- Basic familiarity with Swift structs,
@State, and SwiftUI views - An Apple Developer account (free tier is fine for Simulator testing)
Step-by-Step Build
1. Define the Data Model
Use a SwiftData @Model class to persist each translation so users can review their history later.
import SwiftData
import Foundation
@Model
final class MorseEntry {
var id: UUID
var inputText: String
var morseCode: String
var createdAt: Date
init(inputText: String, morseCode: String) {
self.id = UUID()
self.inputText = inputText
self.morseCode = morseCode
self.createdAt = Date()
}
}
2. Build the Translator UI
Create a SwiftUI view with a text field that converts input to Morse code live as the user types.
import SwiftUI
struct TranslatorView: View {
@State private var inputText = ""
@State private var morseOutput = ""
var body: some View {
VStack(alignment: .leading, spacing: 16) {
TextField("Type text here…", text: $inputText)
.textFieldStyle(.roundedBorder)
.onChange(of: inputText) { _, newValue in
morseOutput = MorseEncoder.encode(newValue)
}
Text(morseOutput.isEmpty ? "— — · —" : morseOutput)
.font(.system(.body, design: .monospaced))
.foregroundStyle(morseOutput.isEmpty ? .secondary : .primary)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color(.secondarySystemBackground))
.cornerRadius(10)
}
.padding()
.navigationTitle("Translator")
}
}
3. Learn and Translate with AVFoundation Audio
Wire up AVFoundation to generate a sine-wave tone so users can hear each dot and dash played at the correct timing ratio.
import AVFoundation
@Observable
final class MorsePlayer {
private let engine = AVAudioEngine()
private let node = AVAudioPlayerNode()
private let dotDuration = 0.12
func play(morse: String) {
Task {
for char in morse {
switch char {
case ".": await tone(duration: dotDuration)
case "-": await tone(duration: dotDuration * 3)
case " ": try? await Task.sleep(for: .seconds(dotDuration))
default: break
}
try? await Task.sleep(for: .seconds(dotDuration))
}
}
}
private func tone(duration: Double) async {
// Render a 700 Hz sine buffer via AVAudioEngine and schedule on node
}
}
Common Pitfalls
- Silent audio on device: Always call
try AVAudioSession.sharedInstance().setActive(true)before starting yourAVAudioEngine, or playback will silently fail on physical hardware. - Blocking the main thread: Generate PCM sample buffers on a background
Task— computing long sequences on the main actor will freeze your UI mid-translation. - Encoding edge cases: Numbers, punctuation, and non-ASCII characters each need their own lookup entries; a missing key will crash a force-unwrap. Use optional chaining or a safe default.
Monetization: One-Time Purchase
A one-time purchase model suits a Morse Code app perfectly — users pay once and own the full feature set forever with no subscription fatigue. Implement it via StoreKit 2's Product.purchase() API: gate advanced features (custom WPM speed, alphabet quiz mode, history export) behind a .nonConsumable in-app purchase, then use Transaction.currentEntitlements to unlock them on every launch without a server.
Ship Faster with Soarias
Soarias scaffolds your entire SwiftUI project — @Model classes, StoreKit paywall, App Store screenshots, and fastlane lanes — in minutes from a single prompt inside Claude Code. For a beginner app like this, that eliminates roughly a day of boilerplate wiring and lets you focus entirely on perfecting the dot-dash audio engine and learning quiz flow.
Related Tutorials
FAQ
Do I need an Apple Developer account to build this?
No — you can build and run the app on the iOS Simulator with a free Apple ID. You only need a paid Apple Developer account ($99/year) when you're ready to install on a physical device via TestFlight or submit to the App Store.
How do I submit my Morse Code app to the App Store?
Archive your app in Xcode (Product → Archive), then upload via the Organizer window to App Store Connect. Complete your metadata, screenshots, and privacy nutrition labels, set your one-time purchase price, and click Submit for Review. Apple typically reviews beginner utility apps within 24–48 hours.
Last reviewed: 2026-05-12 by the Soarias team.