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

2

4

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?
Mcbrayer answered 2/6, 2018 at 20:57 Comment(2)
What do you mean by module related files? The library sources are specified by the source_files attribute in the podspec file.Diffractive
@PaulBeusterien see the pic jmp.sh/Y8bfI4L right after the project creation, it shows up like that. It has those files under Support Files, and under Targets you see MyLibrary. If I run pod install on that project, that target and those files will be gone (which makes the Pod no longer work as a module)Mcbrayer
O
1

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.

Ombre answered 16/10, 2018 at 20:47 Comment(2)
This post definitely helped me figure out why my own files were getting deleted (moving them to MyLibrary/Classes caused them to show back up in Xcode) - but any groups I create are still destroyed. When I run pod install all of my files get dumped to a flat file structure in Xcode. Is there a solution to this?Transposition
You should create directories inside Classes, afterwards they will become groups in Xcode.Ombre
G
1

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.

Guglielmo answered 23/2, 2021 at 2:47 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.