Creating Your Own CocoaPods Pod

Introduction This is probably the last post before the next intermission. The project needed an image picker control, so I found a Swift project, spent two days porting it to Objective-C, and then decided to publish it as a to share with everyone. Create the Project First, create a new project on . Using the current project as an example: Then clone it locally, add the source code and resources, commit, and push to the master branch. These are all standard git operations — no need to go into detail here. A quick note on open-source licenses — MIT is generally a good choice for most projects: One important thing to note: publishing a pod requires a tagged version. So you need to create a tag and push it. Preparing Your Pod First, register with CocoaPods trunk (similar to creating an account): Check your email, click the verification link, then confirm in the terminal: Create the Podspec File This file is a Ruby file, and its fields are self-explanatory. A few parameters worth noting: 1. **: The license type used by the pod. Choose the one that matches your project. 2. : The path to your source files. Note that this path is relative to the podspec file. 3. **: The frameworks your pod depends on. Do not include the extension. You can refer to my file ImagePicker-Objective-C.podspec as an example. Validating the Pod Set the version number and tag (I didn't notice any visible changes after running these): Run the validation command: There are errors: the license and description fields need to be fixed. But what about the error? A Stack Overflow search suggested the tool path was broken. I then remembered I had renamed my Xcode installations to Xcode7 and Xcode8 the day before — that must have broken the command-line tool symlink. Renaming them back to Xcode fixed it, and validation passed. Demo Providing a demo for others to reference is always the more polished approach. I pulled in the existing test code, and the project structure looks like this: The Podfile: After running , you need to remove the original control source files and use the ones provided by the pod instead. Build and run — no issues. Resource Handling Uploading the Podspec File For a pod to be truly usable, one final step is required: uploading the podspec file to the official CocoaPods Specs repository so it becomes a real pod dependency that others can use. Fork and clone the Specs repository (this can take a while — I was using the GitHub desktop client). The convention for storing podspec files in the Specs repository is: folder named after the pod -folder named after the version -podspec file OK, time to upload... After half an hour, I decided to try uploading the file directly to GitHub. After looking into it, it seemed there was no way to upload or create directories through the web UI. Later I found another method: use the command directly. It seems you don't need to sync via git every time. Let's try it. From the project directory: I had switched to my home computer, and every new terminal environment requires re-authentication: Authentication done. Now run: References CocoaPods In Depth — Creating a Pod How to Publish Your Open-Source Framework to CocoaPods Code All the code in this article can be found on my GitHub .