grez grez - 7 months ago 41
Swift Question

Creating a CocoaPod from Cocoa Touch Framework

I have a Cocoa Touch Framework written in Swift that I wish to distribute as a CocoaPod.

The idea is that this will be a closed-source distribution since only the public headers are exposed.

In my podspec I have set the source as the github repo containing my framework. I have also added:

s.public_header_files = "mylibrary.framework/Headers/*.h"
s.preserve_paths = "mylibrary.framework"
s.vendored_frameworks = "mylibrary.framework"


I pushed this up to the trunk. When I install the pod in a new project, I import the module just fine, but it is unable to find the classes I am attempting to use from the framework.

Can someone tell me what the correct way to do this is?

Answer

The reason I was getting "Use of unresolved identifier" errors when I was trying to use my public classes is because my header file mylibrary-Swift.h was not getting exposed properly.

I was able to fix this issue by naming my header file explicitly in my podspec like this:

s.public_header_files = "mylibrary.framework/Headers/mylibary-Swift.h"

After I pushed this new podspec I am able to use my public classes and methods.