Access Control
Access modifiers serve not only to encapsulate our code. But they can also speed up the runtime of our application. These modifiers are private
and final
. The final
I use for all classes.
More information here
Structure
Try to use structures instead of classes. Because structures are more secure (passing by value, not by reference) and structures are stored in a stack
, which is much faster to access than the heap
(where our objects are stored). Also, because the structure is stored in a stack
, it does not increase the ARC
counter.
Clousure
Non-escaping
- Better optimized
- Do not increase ARC counter
Escaping
- When you assign clousure become escaping
- Require
self
to capture context
Exception
Swift has no exceptions like other languages, the only exceptions left are in Objective-C, the main reasons are unstable operation, horrible performance and memory leaks
Layout and AutoLayout
Layout - responsible for placing the view on the screen, and also serves as a process for calculating the frame.
AutoLayout - Almost the same, but the calculation process is automatic.
How often do you crash because of AutoLayout? And memory problems? And a console full of AutoLayout errors?
These are the main reasons why auto layout is evil, but unfortunately it is very common, but nevertheless try to use the normal Layout.
But please do not mix both in one project :)
UIView responsibility
- Display.
- Animations.
- Layout and AutoLayout.
- UIResponder.
- Hierarchy views
CALayer
The two items in the UIView's area of responsibility are handled by CALayer. The main reasons for using it:
- Optimizing
- Caching
- Using GPU
UIResponder
Handler of any user input in the UIKit application
Top comments (0)