Swift.iOS: CocoaPods – The Workspace

In this lesson

You may notice when installing pods from your Podfile for the first time in CocoaPods, that CocoaPods creates a workspace file for you. This workspace file is important and you should be using it from now on. Watch and see why!

Kyle Roberts
Swift Guru at Large

Kyle's Series

Transcript

Tap on time to skip ahead

00:11

Let’s say you have run a pod install for your project and you’ve installed some CocoaPods. In this case, five dependencies from the Podfile and six total. Now, you notice that in your project directory in Finder there is a workspace file for Xcode. A workspace is the same as project file but multiple project files can be added to it. When you run CocoaPods, if there’s not an existing workspace for your project already, it’s going to create one. It’s going to add your original project to it as well as the Pods project. I think this also happens when you run pod init to create the Podfile for you.

00:58

What’s important about this workspace file is now that it has CocoaPods installed to it, you are now going to need to use that from now on. If I were to open just the project file and attempt to run that it is going to have errors and that’s because it won’t be able to import any of the CocoaPods that we’ve actually installed. In this case, we will see an error show up here in app delegate for unable to find MagicalRecord. I guess it found this one first. In this case, it won’t be able to find the SwiftyJSON library installed via CocoaPods in this DataManager class.

01:39

We close that and we open this workspace file and we can verify here that there is a SwiftyJSON workspace file installed. Below that is actually the source for SwiftyJSON that you can view on GitHub or whatever else. It’s actually a locked file. If you wanted to edit anything, it tells you that it’s a locked file. CocoaPods automatically locks all of these source files so you can’t change them. The only thing you ever have to worry about is that your Podfile is actually within the Pods project so you can edit it from Xcode in the Pods project and make whatever changes you need there.

02:27

Running pod install should create this workspace file with your original project and the Pods project. As long as you’re using CocoaPods you should always be using the workspace and never the project. Even importing any of the CocoaPods, you will not be able to run anything from just the project file itself. The workspace is where it’s at now.

Additional Info

Register to get access to additional resources and info.