问题
I installed Cocoapods using the terminal and everything went well, but I cant seem to figure out how to integrate it into my Xcode project. I change the directory to the main folder that contains the Xcode project and type $ pod init
which creates an initial Podfile in the Xcode project folder. Then I open the Podfile in Xcode and make it look like this:
platform :ios, '9.0'
use_frameworks!
target 'MyApp' do
pod "ForecastIO"
end
Next, I go back to the terminal and type $ pod install
and everything goes well. The problem is none of the files show up in the project directory inside of Xcode, yet they are in the Finder folder that contains all the project files. I tried dragging the new files into the project directory manually, but some of them still do not show up and the syntax for the Podfile code is not highlighted. Also doesn't allow me to import the cocoapod that it supposedly just installed. I am new to all of this and I'm probably missing something simple, but I cannot figure it out. Any help is appreciated.
Tl;dr How to implement ForecastIO Cocoapod into an Xcode project?
Lint to ForecastIO Pod Info: https://cocoapods.org/pods/ForecastIO
回答1:
Your opening the YourProjectHere.xcodeproj when you need to be opening the YourProjectHere.xcworkspace
Create a new project in Xcode
Go into your terminal and run this command from the same folder that your YourProjectHere.xcodeproj is located in
$ pod init
- Edit your Podfile
Run this command from the same folder that your YourProjectHere.xcodeproj is located in
$ pod install
A workspace should now be created. Run this command from the same folder that your YourProjectHere.xcodeproj is located in
$ open YourProjectHere.xcworkspace/
回答2:
When you integrate a pod and a subsequent podfile to use with your project, it works alongside your application, not embedded within it anymore. Therefore, you will have to use the workspace file (the white one, not the blue) from here on out. It's a higher scoped file, because it encompasses both your project and the pods directory as a project.
It's common practice to close your application anyway when doing a pod install, and reopen the workspace afterwards. Some people have issues immediately importing a pod, so I would also build first with the pod installed, and then build again with the import statement.
回答3:
I know its too late to reply but I don't see any confirmed Answer for this question yet. In my case I've two versions of Xcode viz. 7.3.1 & 8.2.1 (for some reason I've to maintain it as my code is in Swift 2.3 and I'm using a couple of libraries). So when I tried to run pod install, the pods were getting downloaded and I could see them in Finder but the command was not Generating any WorkSpace file. I googled and landed on this question but I didn't find anything here that helped me get through the issue.
- Well, I found the solution myself..
- In Xcode, Go to Preferences >> Locations
- Select proper version of Xcode in Command Line Tools
- Run pod install command in terminal
Voila, the workspace file gets generated!! :)
I hope this helps someone who has same issue. Cheers.
来源:https://stackoverflow.com/questions/36481926/using-cocoapods-in-xcode-7-3