My Top Swift 4 Extensions You Might Like
Whenever I start building a new iOS app I transfer my favourite extensions from one project to another one. The more I code the more I realise how life becomes easier with these amazing helpers.
In this article I would like to share my favourite Swift extensions I use on daily basis.
Currently I work on migrating UI of the app from a storyboard to code and of course there are some handy dandy extensions I can’t live without.
- When you want to pin your view to the edges of the superview:
- This one is used to set some specific constraints, width or height:
- In case if you need to handle setting constraints with safeAreaLayoutGuide:
- It’s not necessary anymore to create a constant with cellId, all you need is to pass cell’s class name as a cell type with .self in the end:
- A color extension is very useful when you want to save some space and make sure you pass a correct color code. You can specify RGB color:
- Also you can convert HEX to UIColor in this way:
- When you programmatically create buttons, labels or textfields some of them you might customize with a convenience initialiser:
Extensions are very powerful and can be used in many other ways to make your code look cleaner, more readable and easy to understand.
This is my first attemp on Medium to put some knowledge and make someone’s life easier. I would appreciate any support from you guys and thanks for reading!
Enjoy your day and stay positive :)