For those of you used to Android development, you know that file called R that’s autogenerated by Android Studio and gives you access to the resources inside your application. By using this file you have flexibility to change your resources, and have the compiler alerting you about misspellings or missing resources that you are referencing on your project. This is especially great for keeping your sanity when dealing with large projects.
I’m a huge fan of the R file on Android, but unfortunately Apple didn’t implement such thing on Xcode. So for us iOS developers we have to deal with strings everywhere referencing our resources, which in the end just causes mess and ugliness in the code. Luckily the great developer community thought the same way, and decided to create a pod called R Swift. You can probably guess what it does: it replicates all the functionalities of the R file from Android in the iOS environment.
Introducing R Swift
R Swift is a great pod that allows you to instantiate your resources easily. You can use it for colours, files, fonts, images, nibs, reuse identifiers, segues and storyboards. Every time you add something new, Xcode will autogenerate an updated R file with the new resources, just like what Android developers had for years already before us.
After I started using R swift it felt a bit strange, although I knew the Android way, it didn’t feel natural for me in the first days. But, after getting used to it I saw my productivity increasing. No more strings everywhere to get images or segue identifiers and having auto complete for my resource names. On top of that, if I change any resource name or remove it the compiler tells me that something doesn’t exist anymore and where it’s failing.
As a conclusion, here you can see the difference in a before and after picture: