The first step in putting together a custom pod is creating a base project. In this video, go through creating a new project library using the template provided by CocoaPods.
- [Instructor] We need to create the actual pod library project on our desktop and lucky for us, CocoaPods has a utility command to help us generate a complete template. Let's open up terminal again, and I want my project to be saved on the desktop, so I'm going to change directory to desktop. Now, let's run the create command: pod lib create and then the name of the project folder. Now, this should match the GitHub repo, so in my case it's going to be HFSuperImages.
Now, this is going to start a prompt form that we need to fill out. Now, let's start with the language. We want our pod to be written in Swift, so we can either hit Enter since the Swift option is already underlined, or manually type it in. So here I'm just going to hit Enter. And I would like a demo application with my library, so I'm going to hit Enter again. And as far as testing frameworks, I don't want to use any so I'm going to type in, "None." And for view-based testing, I'm also going to type in, "No." When the create command is finished installing, you'll see that our pod has been installed, highlighted in bright green, and our pod installation is complete.
We're also going to see that Xcode automatically opens the .workspace project file. Now, since we're using Xcode 9, we're going to get a project settings warning right away. So go ahead and click on it in the navigator and go down to Update to recommended settings. And here I'm going to leave everything as default and just hit Perform Changes. Now, if you close everything and go back to your desktop, you'll see that your pod library folder has been created. Now, the last thing we need to do here is push our new pod library to the GitHub repository we created in the previous video.
For that, GitHub has given us some easy instructions on the repo page. So navigate back to terminal and clear the log again, Command + K, and we need to navigate to the pods library root folder. So let's say, "Cd HFSuperImages." Now that I'm in here, let's do some Git commands. First, we're going to say, "Git init" and since the pod library creation command already initialized one, it's just going to re-initialize it.
Now we're going to add all our files from our new project to our Git. Git add, dash capital A. Next, we're going to add our first commit, Git commit, dash M, quotes, and in here I'm going to say, "Initial commit "with pod lib template." Beautiful. All our files have now been added. And I'm just going to go ahead and clear the log once again. Now, if you go back to your GitHub page, you'll see that we have a very long line here: git remote add origin.
So go ahead and copy that with Command + C, head back to terminal, and paste it in with Command + V. Now we've hooked up our local copy to our GitHub repo. Now the last bit of magic, we're going to push all our local files up to GitHub. Git push, dash U, origin master. And this might ask you for username and password, so go ahead and enter those. Beautiful.
We've got our branch master set up and all our files added. So head back to your repo page and let's refresh. We should see all our project files in there with the repo name, description, and our most recent commit message we included with our first push. All right, this looks great. Just a note here, there's no right order for when to create a GitHub repo versus creating the actual pod project on your local machine. I like to connect the repo and the default library set-up together without any additional code, so I'm sure that everything is working before moving on.
But ultimately that decision is up to you. You could just as easily have done all your pod implementations before doing this link. Now that everything is synced up between our local machine and our GitHub repo, we're ready to start fleshing out the pod itself. We'll take a look at the base project and the generated Podspec up next.