Skip to content

donatogomez/MainActorCounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MainActorCounter

A simple SwiftUI app that demonstrates how and when to use @MainActor with @Observable in Swift 6.

βœ… Features

  • Built with Swift 6 and SwiftUI
  • Uses @Observable with @MainActor
  • Demonstrates proper state handling without @StateObject
  • Includes both a safe and an unsafe version to illustrate concurrency errors

πŸ“¦ Project Structure

MainActorCounter/
β”œβ”€β”€ Models/
β”‚   └── CounterModel.swift
β”œβ”€β”€ Views/
β”‚   └── CounterView.swift
└── MainActorCounterApp.swift

πŸ’‘ How to Use

  1. Open MainActorCounter.xcodeproj in Xcode
  2. Choose a simulator
  3. Run the app
  4. Tap the increment button and watch the state update safely on the main thread

⚠️ Note: If you're using a free Apple Developer account, you may hit the 3-app install limit on physical devices.

πŸ“š Related Article

Check out the full explanation here: πŸ‘‰ Read on Medium

πŸ§‘β€πŸ’» Author

Donato GΓ³mez LinkedIn | GitHub

About

Minimal SwiftUI demo using @mainactor and @observable to show concurrency-safe UI state updates in Swift 6.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages