How to Create a CocoaPod in Swift | Ray Wenderlich

In this tutorial, you’ll learn how to create a CocoaPod containing your Swift code, assets, and storyboard files. You’ll also learn all about Podspec files.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5823-how-to-create-a-cocoapod-in-swift

Very nice tutorial, Thanks. However why do not use dynamic libraries. Is it because it is technically not possible or is it your choice? Also, can we use one git repo only instead of two?

@keeganrush Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hey @idevelopper, I’m glad you liked it! You can use dynamic libraries with CocoaPods, it’s always been the standard way to use CocoaPods, with the ability to use static libraries only introduced in CocoaPods 1.5.0. Dynamic frameworks come with a launch-time performance impact that some apps need to avoid, but besides that, you can use them if you wish. See the ‘Using Swift Static Libraries’ section of this tutorial.

As for using one git repo instead of two: it’s entirely possible, although it might get messy, and eliminates the point of using CocoaPods to help us separate out our dependencies! However, your individual needs may vary and you should use what’s best for your project.

Thanks for super fast response while the keynote will start! With dynamic libraries the starter time is faster, right? Why some applications needs to avoid this?

EDIT: Sorry but am I confusing Dynamic Library vs Dynamic Framework?

Sorry that this reply is a bit later @idevelopper! I think you are confusing them. The distinction is between static vs. dynamic, and static is faster at startup.

Thanks, so no difference between library and framework terms?

For the purposes of this discussion they can be used interchangeably.

There appear to be some issues with the finished project, under the latest Xcode 10.1, using “the new build system”. You’ll notice a warning about duplicated output files (Assets.car), and during runtime, the “background” image doesn’t load (Could not load the "background" image referenced from a nib in the bundle with identifier).

I think this is a new Cocoapods issue, related to the new build system. See https://github.com/CocoaPods/CocoaPods/issues/8122.

Thanks for the tutorial. I tried to follow it until the point from Setting Up Podspec. I am not sure what you’re saying in reference to the private repo. Do you mean it needs to be a private hosted repo on Github or Bitbucket? Or is it just private because it’s located locally on your Mac instead of being hosted?

To add to the confusion with the podspecs, I’m seeing some conflicting or omitted information compared to the cocoapods guides on creating a podfile, in that there’s no mention of pod lib. For this reason this left me confused about what the goal is with this tutorial (I just want to create a public pod library that anyone can use), and for that reason I decided to abandon it and use the cocoapods guide instead
which is probably what I should’ve done originally, but I tend to default to RW first for things I haven’t done before.

You might want to explain the goal of what you’re trying to do more, and look into the conflicting information in the guide.

Thanks for the heads up, @y2kdar! I see the issue as well. I’ll tend to it shortly.

Hi @post, there is no mention of a private repo, only a private Podspec :]. This is any Podspec that is not published in the CocoaPods public Specs repo.

As for pod lib, that could refer to one of two commands:

  • pod lib create, which bootstraps the Pod creation process
  • pod lib lint, which verifies the setup of your Pod

Both aren’t strictly needed in the creation of a Pod, and are described CocoaPods Guides which are linked to in the Where to Go From Here? section of this post.

I hope that clears things up for you? Let me know if there’s anything else!

@y2kdar discovered an issue with the finished project using Xcode 10.1. During runtime, the “background” image doesn’t load. The following warning appears in the Console:

Could not load the "background" image referenced from a nib in the bundle with identifier

This is believed to be caused by CocoaPods, and may be a problem until CocoaPods releases an update with a fix. In the meantime, you can fix this by using the Legacy Build System. In the Xcode menu, select File / Workspace Settings. For Build System, select “Legacy Build System”.

@keeganrush I noticed a workaround for you that works. If you remove Images.xcassets from the “Copy Bundle Resources” phase, then the warning about Assets.car goes away, and the background image starts working again.

Hi, I’m having an issue with the pod repo push command ; when I run it, I get the following error :

[!] /usr/bin/git -C /Users/ericlemaitre/.cocoapods/repos/mzvPodSpecs pull
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.

And when I run pod repo list, my Podspecs repo has an “unknown” git instead of “master”


mzvPodSpecs
Type: git (unknown)
URL:  https://github.com/Ericlm/mzvPodSpecs.git
Path: /Users/ericlemaitre/.cocoapods/repos/mzvPodSpecs`

Do you have an idea of where I made a mistake ?

@keeganrush Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @ericlm, your podspecs repo is private. Could you make it public, along with your pod repo, so that I can try and see what’s wrong?

Okay, I made them public.

@ericlm, it seems that the problem is because your mzvPodSpecs repo is empty. The latest version of CocoaPods appears to require you to have a commit in your podspecs repo before you can run pod repo push. You should see something like this in your repository:

image

Please click the README link in your repository, as seen in the above image, to add a new commit with a README file. After your repository has a commit in it, you should be able to pod repo push to your heart’s content :]

1 Like

Yeah ! It’s working great now, thank you very much ! :grinning: