SnapKit: Make Auto Layout Easy for iOS App Development

Martin Vincent
MonsterTechStudio
Published in
2 min readMar 29, 2018
SnapKit — NSScreencast

Why SnapKit

We all create constraints one way or another. Constraints can be made in Interface Builder, or programmatically with pure code. Not all developers have the same preferences; part of developers like using Interface Builder, part of developers like coding the constraints. There are also people who are doing both.
So, talking about creating constraints programmatically, it’s not that difficult to specify them as far as you know the kind of constraints you need and how they should be combined. But this is often proved to be a cumbersome work because a lot of stuff is needed to be written in order to set all constraints up properly. At the end, it’s easy to end up with big fragments of code that configure constraints which describe the relationship between views, offsets, constants, and so on, but it’s hard to read and modify them. And here’s where SnapKit gets into play.

With SnapKit it’s extremely easy to create and setup constraints, as the technique that it offers to do that is quite simple, and on top of that the amount of code required is way less compared to the traditional way. This inevitably leads to a great advantage; we have a cleaner, easier to review code, which is better manageable than before in most cases. Moreover, it’s easier to focus on the constraints only, without bothering to provide arguments to built-in functions that we don’t really care about

What is SnapKit

According to SnapKit Website

SnapKit is a DSL to make Auto Layout easy on both iOS and OS X.

Simple & Expressive chaining DSL allows building constraints with minimal amounts of code while ensuring they are easy to read and understand.

Type Safe by design to reduce programmer error and keep invalid constraints from being created in the first place for maximized productivity.

Compatible for both iOS and OS X apps installable through Cocoapods or Carthage.

Free to use in all projects and licensed under the flexible MIT license.

To sum up ,SnapKit is a elegant Swift Tool Kit for you when dealing with autolayout dynamically in code.

SnapKit is really easy to use,for more detail usage of snapKit ,please checkout the snapKit documentations

--

--