Podspec File Syntax

In this lesson

There is some awesome syntax available when configuring your podspec for related files. This syntax is slightly regularly expression-y but don’t let that scare you, it’s very easy to use and can save you from pointing to all your files and directories one by one.

Kyle's Series

Transcript

Tap on time to skip ahead

00:11

00:11

Hello world, Kyle here with brax.tv and I’m gonna talk about how you can use some certain syntaxes with in a podspec to find and match different files. So within your podspec there are a lot of properties that you can pass a path or an array or set of paths into to link or unlink certain files to your CocoaPod.

00:40

00:40

And throughout this files section I have tried to illustrate a few examples of those and have also copied in a few examples from the guys at CocoaPods. So of course when you pass a path in you can set the path just to a plain string, using directory/directory/file. But using this other syntax there are ways to possibly include one or more files with the use of only one path.

01:07

01:07

Probably the most common and simple of those of the syntaxes we’ll cover is using an asterisk. So when you pass an asterisk in instead of an actual directory or filename or even a file type. That means that when CocoaPods is, you know, scanning your pods back or whatever it does, it’s going to look for this path SteamReader. And within that any directory and within any directory within the SteamReader directory, it’s going to include any swift file in our source files. So say within the SteamReader directory we also have a directory called, I don’t know, Code. That’s a a great name. And then we just have a bunch of swift files and these swift files could be, you know, CodeOne.swift, CodeTwo.swift. And because we’re actually using an asterisk here, it’s going to find those.

01:59

01:59

Now if we had a swift file with in this SteamReader directory but not within another directory then we’ll also need to include a second separate path and you can do that like this. Just wrap another path in single quotes and specify what other path query syntax you’re going to use and wrap the whole thing in curly braces with a comma in between.

02:24

02:24

Of these special syntaxes, and this one’s a little regular expression-y, here not so much, but whatever characters you may include within angle brackets, CocoaPods will be able to match for those. So in this particular line item here when we’re setting the public header files, and all this sort of just made up, but using. you know, semi realistic paths as an example. We’re going to be looking within the SteamReader directory. And within that, the pub directory for public header files and again we’re going to match for any file name within that and a file type H or M.

03:03

03:03

So in this case it’s probably more related to Objective-C and not necessarily Swift since we’re referencing header and implementation files but another way you can do this is using that regular expression-y stuff I was talking about before and down within the CocoaPods examples, they’re actually going to match with a file type that is two characters long with any alphabetical characters, A through Z, at least in the English alphabet. So according to this, the results that it would find are the CHANGELOG.md and README.md. And this asterisk is searching for any file name and then searching for a two alpha character file type. And in this case they’re both MD.

03:46

03:46

And then on this next line they also have an example of being able to reject a character from our search results. So again they’re searching for any filename and a file type as long is it does not start with the character M and then it can have however many characters after that. Then we went to include that in that path. So out of a header, implementation, and then these MD files. Since these implementation and MD file types start with the letter M, they won’t be included, so we’ll only be including this header file here.

04:20

04:20

And one more thing that I think would be useful to cover is you can actually instead of just searching character by character like we were with the angle brackets, you can actually wrap multiple characters within curly braces. And within this resource_bundles podspec line item we are specifying path to assets to, great name, and then any file name with a file type of PNG or JPG. And if we wanted to expand on that you can add any number of characters here and just for example, we can add gif to that.