DEV Community

loading...

Random cheat sheet for IOS-Developer

adiks profile image Anton Dikson ・2 min read

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

  1. Better optimized
  2. Do not increase ARC counter

Escaping

  1. When you assign clousure become escaping
  2. 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

  1. Display.
  2. Animations.
  3. Layout and AutoLayout.
  4. UIResponder.
  5. Hierarchy views

CALayer

The two items in the UIView's area of responsibility are handled by CALayer. The main reasons for using it:

  1. Optimizing
  2. Caching
  3. Using GPU

UIResponder

Handler of any user input in the UIKit application

Discussion (0)

Forem Open with the Forem app