Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Never do blocking I/O or heavy work on the main thread
Synchronous network/disk/CPU work on the main thread freezes the UI; move it to a background queue or async/await.
Bad example
| 1 | let data = try! Data(contentsOf: remoteURL) // on main |
Explanation (EN)
Synchronous network or disk access prevents the UI thread from processing interaction and rendering.
Objašnjenje (HR)
Good example
| 1 | let data = try await URLSession.shared.data(from: remoteURL).0 |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
In an interactive UI, use a nonblocking platform API for network/disk work and move expensive CPU work off the UI executor while returning UI updates to it.
Exceptions / Tradeoffs (EN)
Marking a CPU-heavy function async does not itself move execution off the main thread. Keep small synchronous work where it is known to fit the frame budget.