Cocoapods: Is there any way to programatically get the pod version set in .podspec?

Created on 22 Mar 2016  路  6Comments  路  Source: CocoaPods/CocoaPods

I'm working on a library that's distributed as a pod. I have it in a workspace together with an example app that uses it. For a certain use case, I need the library to be able to get its own version (the one set in its .podspec) in code. If I get the version using [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"], though, I end up with the app version instead of the library one, which is not what I want.

Is there any way to get the version that's set in the .podspec?

I noticed that FMDB has the version hardcoded but I'd like to avoid that, if possible. Does any one know of examples from other libraries that get their own version?

Most helpful comment

@rafaelcsa Why is this closed? The question was not to get the value from info.plist but from .podspec?!

All 6 comments

This is what you're looking for : [[NSBundle bundleForClass:self.class] objectForInfoDictionaryKey: @"CFBundleShortVersionString"]

Thanks @ThibaultVlacich!

@rafaelcsa Did that actually work? I am getting the version from the .plist, not the one I set in the .podspec file.

@ThibaultVlacich Are you sure about that solution? Am i doing something wrong?

@rafaelcsa Why is this closed? The question was not to get the value from info.plist but from .podspec?!

@DominicFrei I ended up by writing the pod spec-version to the info.plist (with parsing and agvtool) while pushing a pod update.

The solution @ThibaultVlacich provided works for pods which are not marked as static frameworks.
However, if your pod is a static framework (i.e. you have s.static_framework = true in your podspec) then this solution is not an option.

Have anyone tried to get pod version programmatically for a static framework?

Was this page helpful?
0 / 5 - 0 ratings