1. Home
  2. /
  3. Swiftui
  4. /
  5. Simple Todo App

Simple Todo App - Swiftui Typing CST Test

Loading…

Simple Todo App — Swiftui Code

Demonstrates a simple SwiftUI app with a Todo list, adding tasks, and displaying them using SwiftUI List and State management.

import SwiftUI

struct ContentView: View {
	@State private var todos: [String] = []
	@State private var newTodo: String = ""

	var body: some View {
		NavigationView {
		VStack {
		HStack {
		TextField("New Todo", text: $newTodo)
		.textFieldStyle(RoundedBorderTextFieldStyle())
		Button("Add") {
		if !newTodo.isEmpty {
		todos.append(newTodo)
		newTodo = ""
		}
		}
		}.padding()
		List(todos, id: \ .self) { todo in
		Text(todo)
		}
		}
		.navigationTitle("Todo App")
		}
	}
}

@main
struct TodoApp: App {
	var body: some Scene {
		WindowGroup {
		ContentView()
		}
	}
}

Swiftui Language Guide

SwiftUI is Apple’s declarative framework for building user interfaces across iOS, macOS, watchOS, and tvOS using Swift. It allows developers to create fully native apps with less code and real-time previews.

Primary Use Cases

  • ▸Native iOS apps with modern UI
  • ▸macOS desktop apps
  • ▸watchOS and tvOS apps
  • ▸Rapid prototyping for Apple platforms
  • ▸Apps leveraging Swift ecosystem and Apple frameworks

Notable Features

  • ▸Declarative syntax for UI building
  • ▸Live preview in Xcode
  • ▸Cross-Apple-platform support
  • ▸Seamless integration with Swift and Combine
  • ▸Supports animations, gestures, and adaptive layouts

Origin & Creator

Created by Apple in 2019, SwiftUI was introduced to unify UI development across Apple platforms and replace UIKit/AppKit with a declarative approach.

Industrial Note

Perfect for Apple ecosystem apps where full native performance, Swift language, and declarative UI are priorities.

More Swiftui Typing Exercises

SwiftUI Counter AppSwiftUI Step CounterSwiftUI Dark Mode CounterSwiftUI Multi CounterSwiftUI Auto Increment CounterSwiftUI Todo With PrioritySwiftUI Countdown TimerSwiftUI Counter With Alert

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher