CocoaPods Podfile Comments And Logging

In this lesson

Did you know you can add comments and logging to your Podfile? Well you can and its easy peasy. It’s all in Ruby so if you know your printing and pound symbols, you are good to go.

Kyle Roberts
Swift Guru at Large

Kyle's Series


Tap on time to skip ahead


Hello world. Kyle here with Let’s talk about how to use comments and print statements in a Podfile. Here I have it already set up in my Podfile for SteamReader with an example of both. Podfile is in fact written in Ruby code so that comments and console logs that we’ll be making are just going to be using standard Ruby put statements for logs and prefixing lines with the hashtag pound symbol for a code comment.


Let’s start with comments because it’s the easiest. Any line that you want to make a comment, you just have to preface with a pound symbol. The line I have already here commented out is a Pod line item for Spring, which is a popular animation open source resource in Swift. I just have it commented out because I haven’t used it yet. I am wanting to remember to implement it at some point. So I just have it commented out. I could even be more descriptive and say, “reminder to install Spring when ready to beautify with animations.” Since there’s not many animations in SteamReader yet, it’s mostly scrolling in a table view. That’s comments. Very easy.


Then, print statements is a little different. This bottom block of code here is actually copied straight from the CocoaPods website. They have this as an example of so printing they do. What this does, is that right after the install of all of the Pods, we’re going to loop through each pod and then print that pod’s name to the log. We can actually concatenate that with some other stringage here. Let’s say, “Installed pod name: “ So then when we do run a pod install we should see that output to the log.


Above that there is a pre-install block which you can also use to run print statements. The actual print syntax is the word puts and then a space and then the string you want. Up above in the pre-install stuff, before we actually install any of the pods, I’m just going to put “Preparing to install pods.” At this point since the pods have not been installed yet, we don’t actually have access to each pod name. But, oh well, we can just put that there and see it in the log output. I’m going to Command+S to save. When I run this pod install, we should see that these comments do not get printed out to the log. Because they are just comments, they are just reminders to the actual code. But these two put statements should be.


Running pod install, it went pretty quickly. This is all standard CocoaPods output, analyzing dependencies, downloading dependencies, and then comparing to our Podfile.lock file with the actual versions we already have installed. Here’s this comment before they are actually installed, “is preparing to install Pods.” Then we’re generating the pods project, which is actually where this project is created and all the pods are added to it. Then the workspace is created. Right after that, we’re looping through all of the pods that we’ve just created. There’s these six actual Pod line items that we’re installing and there is this pod SteamReader one, which is just a general, pseudo pod that it creates for our actual project.


Let’s open up the Podfile again for comparison. And then pod installation complete. We have both of these print statements pointing out to the output of pod install. Then our comments are only staying in the code, as they should.

Additional Info

Register to get access to additional resources and info.