Other Practices
Here are some handy ways to help optimize and improve your code:
-
Prefer let constants to var variables unless you truly need mutable data. The compiler can better optimize your data when it’s guaranteed not to change. The Swift compiler is very good at detecting unmodified var use.
-
Marking classes as final enables the compiler to introduce performance improvements. These improvements depend on moving away from dynamic dispatch, which requires a runtime decision to select which implementations to call. Removing indirect calls for methods and property access greatly improves your code performance.
-
Swift’s whole-module optimization can automatically infer many final declarations by scanning and compiling an entire module at once. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access