Roger Oba
Roger Oba

Reputation: 1420

How do I create a cocoapod framework and add files to it?

I'm creating a private pod and would like it to be used as a module. According to Using Pod Lib Create, in CocoaPods.org:

The first question you're asked is what language you want to build a pod in. For both choices CocoaPods will set up your library as a framework.

In fact, when I run pod lib create MyLibrary, the initial project template they generate does have everything configured to be a framework, so that I can add a class to Development Pods/MyLibrary, and access methods of that class from the sample project simply by importing the module using @import MyLibrary; (or import MyLibrary, in Swift).

The problem lies on the fact that the same page tells us

With the questions over, we run pod install on the newly created Project.

And as soon as I do that, the module-related files are gone, and all the files that I had added to my Development Pods folders are gone. Not only that, the framework Target itself is gone, so it's not even a matter of simply adding the files back again.

What's the correct approach here? I don't seem to find anyone with the same problem.

I'm running Cocoapod v1.5.3

Any help is highly appreciated!

tl;dr:

  1. pod lib create MyLibrary
  2. cd MyLibrary/Example
  3. pod install
  4. Now notice that the project has no module configuration anymore. How can I avoid this?

Upvotes: 4

Views: 3199

Answers (2)

mfaani
mfaani

Reputation: 36287

What's super important is that when you run pod install CocoaPods will look into your PodSpec and only install files that match the source_files criteria mentioned in the PodSpec i.e. the files need to be

  • correct extension
  • correct path.

But basically you have to add the file to the exact directory you want. If you're using groups it gets messed up. So instead of adding a new file using Xcode, just add the new file using Finder and then run pod install.

Not sure why but if I add to the same group that has a similar file at the appropriate directory, Xcode and CocoaPods will just put the file at the top directory.

On a complete tangent:

If you've been pointing locally to to your private pod using :path and then add new files into your private pod, those new files aren't reflect in the repo that pull in the private pod. They'r not reflected because their source control is from another git repo.

As long as you see the new file of your private pod in your main app and your main app compiles then you're good.

Upvotes: 1

dequin
dequin

Reputation: 926

According to the same page:

[!] Note: Due to a Development Pods implementation detail, when you add new/existing files to Pod/Classes or Pod/Assets or update your podspec, you should run pod install or pod update.

In my experience, you have to be very careful when adding new files because they may end up on a different folder than the expected Pods/Classes.

When in doubt, I go to the folder containing the project and search for the missing file and move it to the correct folder.

Upvotes: 1

Related Questions