Swift default actor isolation

스위프트 기본 액터 격리

Set a default isolation domain so UI state access stays with one actor.

···
html
<div class="v"><header><b>ACTOR ISOLATION</b><span id="state"></span></header><main><div class="lanes"><div class="lane" id="mainlane"></div><div class="lane" id="otherlane"></div></div></main><footer>state belongs to one isolation domain</footer></div>
css
.v{width:min(92vw,660px);height:min(86vh,310px);box-sizing:border-box;padding:clamp(9px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);display:flex;flex-direction:column;gap:7px;color:var(--fg);font:500 clamp(15px,3.2vmin,17px)/1.25 var(--font-sans, sans-serif)}.v header,.v footer{display:flex;justify-content:space-between;align-items:center;gap:8px;white-space:nowrap}.v header b{color:var(--accent);font-size:.9em}.v header span,.v footer{color:var(--muted);font-size:.82em}.v main{flex:1;min-height:0;position:relative;overflow:hidden}.v .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.v .active{background:var(--accent)!important;color:var(--bg)!important;border-color:var(--accent)!important}.v .muted{opacity:.28} .lanes{height:100%;display:flex;flex-direction:column;justify-content:center;gap:9px}.lane{height:36%;border:1px solid var(--line);border-radius:6px;display:flex;align-items:center;justify-content:space-around;font:600 .8em ui-monospace,monospace}.lane b{padding:6px;border-radius:4px}.lane.warning{border-color:var(--accent-2)}
js
let n=0;function draw(){document.getElementById("mainlane").innerHTML="<b>MAIN ACTOR</b><b class=active>UI state</b>";document.getElementById("otherlane").innerHTML=n?"<b>BACKGROUND</b><b>crossing requires hop</b>":"<b>BACKGROUND</b><b>independent work</b>";document.getElementById("otherlane").classList.toggle("warning",!!n);document.getElementById("state").textContent=n?"isolated access":"safe lane";n=1-n}draw();setInterval(draw,1300)

Swift 6.2 lets a module or target choose default actor isolation. UI-heavy code can default to MainActor so access rules are consistent across the module.

Putting all work on the main actor can also keep heavy computation there. Mark work that truly needs parallel execution and cross isolation boundaries safely.

When to use

Use it when setting a consistent isolation policy for Swift UI code.

Open as page ↗