Top Tweets for #Mainactor
Adopting Swift 6 strict concurrency. The pattern: immutable Sendable structs for data, @MainActor classes for UI state, actors for shared mutable state. The hard part wasn't the compiler errors — it was figuring out which state needs sharing. #Swift #SwiftConcurrency #iOSDev
Just about to distribute a new update for iBite on the App Store. 🥳Added some new images to advertise the new features.
+ new character customization features
+ players can now send mailbox messages in the house interior
+ profile view updates
+ more firebase data and character items.
+ character customization store with @MainActor and asynchronous code to download server files.
#software #solo #engineer #startup

Having this set to `MainActor` breaks generated things like image resources.
So let it be `nonisolated` — that is the more reasonable option anyways. It will be expected to use in one concurrency domain and not cross boundaries (threads). Created in one actor, used in same actor.
Set Swift version to 6 and Strict Concurrency to Complete though.
This disallows making most of concurrency related mistakes.
It is also a good idea to enable explicitly built modules and member import visibility to YES.
This allows you to actually ensure proper isolation and responsibility segregation.
@ MainActor
Should i change this ?
what are the best practices regarding this setting ?

I solved this by making the extensions static functions that accept only Sendable values and objects, while keeping all non-Sendable objects on the MainActor.
You could set the module's default actor to MainActor, but I think that is a bad practice because it forces client code to access the entire module from the MainActor. What do you think?
Most of the changes were required because I had split my utility extensions into a separate module. The issue is that self in the main app lives on the MainActor, while the extensions in the other module are non-isolated, which triggers actor-isolation errors.
For example, I defined a helper export function as an extension on AVAssetExportSession. Since AVAssetExportSession is not Sendable, it raises a compile error.
Have you tried Swift 6.2 with default MainActor isolation?
My project built with almost no changes on Swift 6.2, but turning on default MainActor required significant refactoring, and I’m wondering if that is considered best practice.

💡 iOS Programming Tip:
Use @MainActor on UI code to ensure it always runs on the main thread.
Example:
@MainActor
func updateLabel() {
titleLabel.text = "Hello, iOS!"
}
No more “UI updates on background thread” warnings 🚀.

@david_hall_atx ☝️ write a @ MainActor function which sets animatedCards = true and your code will be simpler and more understandable.
Avoid the old DispatchQueue that new developers won’t manage correctly during maintenance.
🧵 Say goodbye to data races.
Apple's #SwiftConcurrency introduces powerful tools like @MainActor, @globalActor, and @_inheritActorContext.
Actor-Based Isolation is the future. Here's why
👉 https://t.co/CpHvlIUSdB
#iOSDev #SwiftLang #Concurrency #iOS
🧵 Say goodbye to data races.
Apple's #SwiftConcurrency introduces powerful tools like @MainActor, @globalActor, and @_inheritActorContext.
Actor-Based Isolation is the future. Here's why
👉 https://t.co/CpHvlIUSdB
#iOSDev #SwiftLang #Concurrency #iOS
@thaipham278 Almost everything except for concurrency primitives in native iOS like Task, escaping, MainActor, asyncAfter, etc
@milesofmichael A MainActor runs on the main thread, an Actor
“execute tasks on a shared global concurrency thread pool. This pool is shared by all default actors and tasks, unless an actor or task specified a more specific executor requirement.”
@Vlad_Smolyanoy I have updated two of them. I spent some minutes adding MainActor at the top of every ViewModel.
@Maisomage True, Actors shine in managing concurrency within Swift. But u r right interacting with System APIs can get tricky. reliance on @MainActor can feel like overkill in some cases. Swift’s concurrency model is still evolving & there’s room for improvement with broader system APIs.
@Bhaav_Paji Swift Actors are good, but they are for Swift only 🤷♂️
When you call a System API, with await, which returns an object including other objects, Swift gives no solution except using @ MainActor everywhere 🙅♂️
Adding extensions for every SwiftUI component that does not support concurrency is hard to maintain.
'func withAsync(:_)' is an elegant solution that could be passed as a parameter in another closure. It converts closure into async action with @MainActor implementation.
Sample:
SwiftUI, async/await and Swift 6 used together cause a lot of problems and inconsistencies in the code.😳
I was looking for an elegant solution, and I have created `withAsync(_:)`. It allows me to pass a func as a parameter, stay safe on @MainActor and keep the code readable.🚀

@Marlon_Rugama @mainactor @ MainActor ensures that the code is ran on the thread which manages the Interface.
Some code *must* run on this thread, it is better to use @ MainActor a bit too much than not enough.
When values change in your ViewModel the UI is updated, it must be in the @ MainActor
@Marlon_Rugama Bonjour
UserManagerViewModel is tagged as @ MainActor
This means all accesses must come from code explicitly running in MainActor or from a task with an await call.
MediPetApp is not tagged as @ MainActor.
@hieudinh_ You probably need to make whatever is making this change a MainActor. Can you share your code? It’s impossible to debug without seeing it.
@bengi_trd Obeservable objects are run in MainActor by default in newer swifts
@jimbeanLit @buildinpublic @mainactor Not come across Mainactor yet. I’ll give that a try. I’ve seen a warning to do with that sometimes so I’ll sook it up.
@JohnPill4 @buildinpublic Don’t add default data to published variable. Make a function and have some event to trigger logic then update the published so the UI can update. Also make sure update the published on Main thread. You can add @MainActor infront of class or function to achieve that
@zain_hoda Put the audio stuff in a class then use @MainActor on the class or the function depend on what you try to achieve. That should help resolve the issue. MainActor act like Dispatch async
Thought I could gradually migrate single functions to async await, but it appears a simple change requires a good amount of refactoring (eg. Task, MainActor, etc). 😩
Most Popular Users

Elon Musk 
@elonmusk
239.7M followers

Barack Obama 
@barackobama
118.6M followers

Cristiano Ronaldo 
@cristiano
114.3M followers

Donald J. Trump 
@realdonaldtrump
111.7M followers

Narendra Modi 
@narendramodi
106.9M followers

Rihanna 
@rihanna
98.6M followers

NASA 
@nasa
92.1M followers

Justin Bieber 
@justinbieber
91.7M followers

KATY PERRY 
@katyperry
89.9M followers

Taylor Swift 
@taylorswift13
83.9M followers

Lady Gaga 
@ladygaga
75.4M followers

Virat Kohli 
@imvkohli
73.3M followers

Kim Kardashian 
@kimkardashian
70.8M followers

YouTube 
@youtube
68.6M followers

Neymar Jr 
@neymarjr
66.3M followers

Bill Gates 
@billgates
65.1M followers

Selena Gomez 
@selenagomez
63M followers

The Ellen Show
@theellenshow
62.1M followers

CNN 
@cnn
61.7M followers

X 
@x
60.6M followers




















