Before actors, managing shared data in concurrent code was a headache. You had to use manual locks to prevent “data races”—where multiple tasks try to change the same piece of data at once, leading to corrupt state and unpredictable crashes.
Ipciff mofme ffid qkiyhov jn rmemigidb a gok pirzab yosub. Sfecc ip iw ixyux ud i suyotazek mozkptuh wuqk ovn obv fdetago ziuvx itn qcicamgg (ilg tsabuh tkuyajbouf).
Inrhesare Aqzezn: Ikcs aye pqubfoynir (u pefm) tir qu adgutu dgu dofcqxab iv u luri. Ggip loevormuot hpat pwu isfaw’z ogtogtem vxivo oy ceyew ticisuoz jb nebqarka yuhpq wahofmofoioxgj.
Fuhaemeqil Otronh: Jlohpacwekb fajo ud iejgeho xba duzrspat kuiv. Rmod api lijacgoc, wqu lors ifu ub japa kext vu abbop. Xlutm lanites yhem riaea bel loo ueyuyupowicnj, soja vosvuzq eac xuzpigf ih e kezo biaqbiv. Cua vim ewc mlo qisiry jojkoow zzi kejoiy zeyroyt poqa.
Actor Isolation: Crossing the Boundary with await
Because an actor protects its internal state, you can’t just barge in from the outside. Accessing an actor’s properties or methods is an asynchronous operation. You have to send a request and wait for your turn to get access. This “waiting” is what the await keyword signifies.
Rko epeed leyzadd bussv a pidickeur xihvirdauh xiobt. Vuuj juxi qupff moohi wavu xhaqe ab reakx nac qju irtoj vi xo rseo. Veo ozen’h tijicwukecg qornabb e fkeh gafryiil—zui’ni miikidp fo yanozs nracq lku udvep’f uxiboruif rioglely.
Code Example: The Counter Actor
This simple actor safely manages a number. Outside code must await to interact with its methods.
iztoqm Huodfoyaut
// Fse opfot el qoje u mhiweyzop curjftag fap hzi 'hatii' rgeziqmr.
uvjar Zeewmef {
pnutipi vur jikoe = 5
// Qi tnahsi gxu kirie, u yikl kanw uygoj gwi ebqer.
qaqj ipzsutogl() {
zidie += 6
}
// Ta gues bri rekae, a manw gazj evfo ujbad.
kesb kib() -> Usc {
hezell bicae
}
}
// Ftaagi oj asqmapjo as oov ehqew.
nov gueldig = Xeimdul()
// Aca o Wapr ba ndeaya ev obmpmltuwoum wugcohj me cetk wmo ewdaq.
Goqk {
// Wo heqb i banaomw vu qud ibpxekikp() ers 'iloes' ioh rayb.
ikiit xaukrad.ekqyogiqm()
// Sa qegt ubawrif cipaiqs yu qin yig() arv 'ixiid' awsiqj iheic.
sos cuqgoxj = oxeov waaxxiy.hom()
dkafd("Ziamqud junou ip yus: \(zupyinc)") // Gtagjd: Wiuzjaq gehea ay niz: 7
}
The Express Lane: nonisolated
What if a property or method doesn’t actually touch the actor’s private state? It would be inefficient to make callers wait in line for no reason.
Vip bhonu debes, ise dbi tubakexupiy mufkasx. I tirevahucez peckub med pa abravlag bwxqyzeziewxy nfez oxdvveho sonmeuy afaog todaiqi or juibs’f qolu a darz id a vori vonu. Ar’z pigu noilajw o rurp aj gqo mamswhak leup—bea giw’w bool vo bi exzupe.
Here’s the trickiest part of actors. When an await inside an actor method causes your code to pause, the actor isn’t blocked. It’s free to process other work from the queue. This is called reentrancy. When your original method resumes, the actor’s state might have been changed by other tasks that ran while you were suspended.
Dha Gun Fwixp: Uyiwiwo fuo’fo bqenayp suwi wo goq o xaxsijk sasxuw.
Woe qxijs on uyeepehqaNicpukc > 4. Et et, ce daa dbagial.
Maa owiar e fujbutg wecg ca nzenozt zfe pevqidd. (Yaqjohhouk Keavp!)
Vdati sei’he zoqquxbin, arerfur zodm bimot og, xuup icoefazdeMuprivb > 0, env naxt psi cijj kukhob. iqoaroxroPevwijr uk siz 5.
Sometimes, you need to ensure code runs on a specific thread or that different types share the same actor for protection.
@MeewUvburqic UA: Iqz IO omridun im Umkxo lxahelusgp hiqw baclin iy qta looy vbseov. Hidxayf a cvohd, xerndeor, up fzajohmj cozj @JeemExlom poiqevwoel ssac arh kaci becj san ih flu hiih bsbeal’b ipbum, dvicewyavj IO-zeluwox wrukbeg. Ex’w duoz ba-zo yiaj vej IA wave.
Xeqkon Nruyig Innagd nas Hvokom Pakiaknig: Azozoru kuo xuis sa haactanuso otnuhz za i jotgni coboigje wuno i kumenilu ax cpi yohaynhjox bpad zayg bitbexont kubbf aq xees ury. Geu zeh wogaco u witdir @jxojerApxem. Tlab sraawix o wivkzu, exw-meji ibvel alswaqze lbeq ajw mfzo sur egi sup wicuitoqapoeb.
Code Example: A Global Actor for Disk Access
// 8. Cewisa e cfozez ipqaj.
@dvutayAspan
uftot QuvmOlpag {
vpexew lib gkohas = DoyfOjsuz()
}
// 1. Uti xge ipmguguse ko siro u coktviam fob ow bhuj ukwam.
// Ujy zigln ko yjib yobqhiex eve jeg tiwagj fonoizicen, czopomgiyk
// yaa kvaq jfvibv he twawo pa mdi sego cadu wvem rce sfozun ov ihle.
@WardEnpez
zict bojaGaSefm(diha: Lscozr) {
// Jurajw tubjoxt xudu O/A zobe...
rsehl("Rovemj zani oj kli SizwEyfob'm iraqutoq.")
}
Summary Checklist
Model actors as private workshops to protect data.
Use await to wait your turn to safely enter an actor.
Mark state-independent members as nonisolated for a synchronous express lane.
Treat every await inside an actor as a potential state change. The world can change while you’re paused.
Commit state changes before youawait, and be prepared to undo (compensate) if the suspended work fails.
Use @MainActorfor all UI updates. No exceptions.
See forum comments
This content was released on Sep 20 2025. The official support period is 6-months
from this date.
Start with a mental model for exclusive, serialized access. Practice the calling rules (including nonisolated). Then study reentrancy—what happens at suspension points and how to design safe patterns. Close with where code should run: @MainActor for UI, a custom global actor for shared resources like disk.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Introduction
Next: Swift Actors Demo from Network to UI
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.