65

I downloaded a sample project to learn how to make a UIPageViewController, and I am trying to essentially fork that project and need to add a third-party library. Right now, it does not look like I have a .xcworkspace file in my project. When I try and install the cocoapods, I first run

sudo gem install cocoapods - in the specific project directory in my terminal

pod install - in that same directory

I am receiving an error in the terminal "No podfile found in the project directory."

Is this happening because I don't have a .xcworkspace file? Am I installing the podfile correctly?

enter image description here

tccpg288
  • 3,242
  • 5
  • 35
  • 80

5 Answers5

130

Steps to add CocoaPods to manage dependencies in your project:

  1. sudo gem install cocoapods -> This installs CocoaPods as a piece of software on your machine.

  2. Go to the root of your project directory and execute pod init -> This will add a base Podfile to your project.

  3. Add the external dependencies that you have to this Podfile by editing it.

  4. Run pod install which will fetch all the external dependencies mentioned by you, and associate it with a .xcworkspace file of your project. This .xcworkspace file will be generated for you if you already do not have one.

From here on, you should use .xcworkspace file instead of .xcproject / .xcodeproj.

Example Podfile Syntax:

target 'MyApp' do   
pod 'AFNetworking', '~> 3.0'
end

Where AFNetworking is the pod and 3.0 is the specific version that I want to install.

Documentation: Using CocoaPods

Jerry Chong
  • 7,954
  • 4
  • 45
  • 40
Vijay Tholpadi
  • 2,135
  • 1
  • 15
  • 20
  • Can you elaborate on Step 3? I have opened the podfile, and see several items stating target 'App name' followed by 'do' then 'end'. Can I delete this code? – tccpg288 Apr 28 '16 at 22:39
  • Do not delete that code. A Podfile is ruby based. The 'App name' you see here is your `target name`. Inside the `do` and `end` for a target, you mention the pods that you want to add to install to it. – Vijay Tholpadi Apr 29 '16 at 04:43
  • how much time it will take for first time pod install? – GvSharma Aug 21 '18 at 06:51
  • @GvSharma The first time pod install is known to take time as it clones the CocoaPods master spec repo. You can add the argument `--verbose` while running `pod install` to see what's exactly happening. – Vijay Tholpadi Aug 22 '18 at 02:21
  • "From here on, you should use .xcworkspace file instead of .xcproject". Big thanks for that clarification, I had been confused earlier about it. And no other tutorial had mentioned that. – monkSinha Feb 27 '19 at 01:08
  • 2
    If you are using flutter, make sure you are in the ios folder before `pod init` – Graciela Carrillo Aug 19 '21 at 20:21
  • If you're using Flutter, in the terminal `cd ios` then `pod install` – Sharon Atim Mar 27 '23 at 19:49
14

Just posting for anyone that encountered this issue while working on a react native project.

  1. sudo gem install cocoapods this installs cocoa pods to your machine

  2. cd projectDirectory cd into your project directory

  3. cd ios cd into the ios directory of your project, is you list items that are in this folder, you would most likely see a podfile there.

  4. pod install

Excellent Lawrence
  • 946
  • 11
  • 11
8

If you want to add a library from GitHub to your own project, after installing gems, do firstly pod init look at from GitHub cocoapod description and then add it after target line in podfile.

Save and run "pod install".

It would be successfully added on your project.

Jerry Chong
  • 7,954
  • 4
  • 45
  • 40
iamburak
  • 3,508
  • 4
  • 34
  • 65
6

Don't forget to call pod install in the Project folder of your project (not in the root).

Cristan
  • 12,083
  • 7
  • 65
  • 69
0

Open a terminal, if you use VSCode, you can just run the following from the terminal Do a cd <project_name> to your flutter project directory Run cd iOS Then run pod install

Codedman
  • 233
  • 2
  • 10