Podspec Platform Syntax

In this lesson

If you think having separate CocoaPods configuration for different platforms would be nice to have, then you’re in luck. Many podspec properties have multi-platform support so that you can target different platforms for different values of the same property.

Kyle Roberts
Swift Guru at Large

Kyle's Series


Tap on time to skip ahead


Hello world, Kyle here with brax.tv and let’s talk about using some handy dandy platform syntax within a podspec. So within this SteamReaderExample.podspec file that I have within the Git repo for SteamReader, on each line item within the podspec that you can actually specify different platforms for, or target different platforms for different values of these podspec properties I have added a .iOS specifier to them, and that is just as an example.


So any of these lines that are not specifically calling out that they are targeting the iOS platform, they do not support different values for different platforms. But the ones that do have a few values to choose from. And just to point out, you don’t necessarily have to use the target platform specifier. You, you can just as easily use a blanket statement. So instead of saying s, for spec, .iOS.header_mappings_dir. We can just say spec.header_mappings_dir equals this path. And that means that no matter what platform a user is installing this pod for, this value for the header mappings directory is going to go for every platform.


But then if we re add that iOS platform specifier here, then that means only when a user is using this CocoaPod and reading this podspec, and their podfile is defined as using the platform iOS, then will this value be set. So if we’re going to use this CocoaPod, but they had their platform defined as watchOS, that means this specific header mappings directory value will not be set for watchOS.


And just to illustrate all the possible values you can use here when defining platforms, we of course have iOS. There’s also OS X which as far as I know has not been renamed yet to macOS in the CocoaPpd realm, so we can still use osx, probably for the better for backwards compatibility of any older podspecs. There’s also tvOS and as I talked about earlier watchOS. And that’s the podspec platform syntax. 

Additional Info

Register to get access to additional resources and info.