Universal iOS app using CocoaPods - which files to check in into Git? - ios

In Xcode 5 I am developing a universal iOS app - on three different Mac OS machines (on which I happen to have different usernames too - "admin", "alex", etc.)
My project uses the SDWebImage library through CocoaPods and I plan to add few more later.
I would like to keep my project in a Git-repository on GitHub or BitBucket.
I'm confused: which files of my project should I check in into the git repository.
Especially I wonder about 2 groups of files:
The CocoaPods-related (currently I've only checked in the Podfile and Podfile.lock, but there are also Pods.xconfig and Pods, etc.)
And the Xcode-related (should I check in the Workspace Settings? What to do with User Data - admin - ...?)
Here is the screenshot of the commit dialog:
When I run git clean -n -d in my project dir, I see the following:
Would remove Podfile.lock
Would remove Words.xcodeproj/xcuserdata/
Would remove Words.xcworkspace/
And my Podfile contains the following:
platform :ios, '6.0'
pod 'SDWebImage'
UPDATE:
I use a .gitignore containing xcuserdata, but for some reason still see the User Data files in the commit dialog:

This is a bit of a matter of taste and requirements for your projects. There are two schools:
Never check in generated code. Put your xcworkspace, Podfile.lock and Pods folder in .gitignore and never commit them. Instruct developers on your code base to run pod install directly after checkout. This is my preferred choice, and should work fine as long as your pod dependencies point to a specific version or a range of compatible versions.
Check the workspace, lock file and Pods directory into Git with the rest of your code. This is a guarantee that all developers on the project are using the exact same code when they build. Even if your third party dependency removes their code from the Internet, your project is still buildable. However, you now have a lot of source code that is unrelated to your own, version controlled together with your own.
As an aside: you should probably always put "xcuserdata" in your gitignore, maybe even your system-wide git ignore, because other users of your code are probably not interested in your personal Xcode settings.

Related

I've Broken GIT With CocoaPods and Cannot Merge/Commit

This may be a more complicated issue than I am portraying, but after building an iOS app and occasionally using GIT, I am not in a challenging position; I have additional developers I am working with, and there is a need to properly use a repository (BitBucket) for further work.
My project is "complicated" for two reasons;
I am using CocoaPods for third-party dependencies.
I use using GPUImage2, which is a separate .xcproject embedded in my project.
Somehow, everything was working fine (I had a master branch and several branches that various developers have been working on). Things have been complicated whenever I find the need to switch branches or merge branches. Issues related to CocoaPods constantly come up, though endless efforts at the command line typically get us through our challenges.
At this point, we are now trying to merge master into a new feature branch, and have hit the end of the line.
My question: Only one actual project file has a merge conflict. Every other file is related to the .xcworkspace or something with CocoaPods. I would think it would be ideal to remove CocoaPods from GIT control altogether, leaving just the Podfile, which developers can install locally.
Does anyone have suggestions on dealing with CocoaPods and GIT with Xcode projects?
I strongly recommend that you do not add your Pods folder to git, only commit the Podfile and Podfile.lock.
You can do the following to remove the folder:
git rm --cached Pods/

Why Cocoapods ignored when pushing to Git?

As a POC, I created a new repository (on BitBucket) and tried to push a dummy project, everything worked as it should; I tried to apply the same exact process on my actual project, which has cocoapods, it has been pushed successfully, but when I tried to checked it out, I got the source code without the pods!
I viewed the source of the repo, it does not contains the pod directory.
Here are the files that I tried to push (16 files and folders, 192MB Size):
And that's what the repo contains (14 files and folders 121MB Size):
Note that the last tow folders in my local machine (Pods and widget) are not in the repo.
There is no .gitignore file.
Also, I checked:
git push ignore cocoapods
Commit to git after switching to workspace and adding CocoaPods in Xcode?
without any useful results.
Any advice would be appreciated.
CocoaPods is a dependency manager:
The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.
You can run pod install to install the pods for your project, which will create and populate the Pods/ directory.
The reason the Pods/ directory isn't in your repository even in the absence of a .gitignore file is probably that it contains other Git repositories (i.e. directories containing their own .git/ directory). Git doesn't track nested repositories.
(It is also possible that Xcode ignores that directory by default, but I'm not an iOS developer so I can't be sure about that.)

Best approach : Is it good approach to sync pods file on Github

I am using some framework which are integrated with pods . So I want to ask is this good approach to sync these framework on gitHub . For example . In my iOS project I have integrated GoogleMap framework, Should I sync this on Github or i should some reference . I am asking this because When i commit this framework it give me memory issues.
I'd say there's no "best approach" about what should be ignored concerning your pods dependencies.
One would say that it's better to ignore the pods directory to keep your git repository light, but for someone else would say that your pods dependencies are part and parcel of your app, it won't build without it, so you must commit it.
First I chose to include all my pods in my git repo, but I quickly noted that it could be very annoying, given that each time you update one of your dependencies it blows yp your updated commit files list. Now I just include my Podfile and Podfile.lock files and ignore the Pods repository. Just make sure to run pod install each time you pull from the repo.
The main benefit of including all your Pods is to have your project "ready to build", without the need to have CocoaPods installed on your computer to build it first.
For more details, see this related question :
What goes into your .gitignore if you're using CocoaPods?

Xcode 6: What to ignore when committing to SVN so the application can later be checked out and runnable without any extra work?

I want to commit the minimum amount of files and still be able to checkout and have it working without ANY work. This will be specifically used for a Phonegap iOS application. However, any relation to iOS apps will be great.
Essentially you may ignore only the builds/ folder as the files in there are generated every build. Have been working in a project with other develops having only this folder .gitignore'd.
If you wish, you may ignore several other files to make your repository as clean as possible.
Another way to commit as little as possible is to use external library managements, such as CocoaPods. Just remember to ignore Pods/ folder and run pod install when first running the project on a new computer.

Working with git submodules/cocoapods

I am working on a project which includes other repositories from Git.
I would like to keep up to date with these repositories. Know what are the latest features, bug fixes etc.
Qu 1) What is the best way to keep up to date with a repository on Git without receiving emails of all issues reported etc?
After this is complete I would like to know the best way to include these into your project. I understand you can copy the source code into the project, but what are cocoapods/sub modules used for? For example, what is the correct way to update your project with the latest changes to that included repository?
Are there any GUIs for either of these methods as opposed to terminal?
Cocoapods is a great way to include other projects in your Xcode project. The Cocoapods project maintains a list of pod spec files for a many open source libraries, which specify where to download the code and how to integrate them into an existing project. As you noted, you'd traditionally have to add a git submodule, manually add the source files to your project, update your build settings, and so forth. Cocoapods takes care of all of this for you.
I'm not sure of a way to track updates for Github projects without also being notified about issues, but Cocoapods can certainly tell you if any of your 'pods' have become outdated. It's then one command to update them to the latest versions. That said, it's generally best practice to 'lock' your external dependencies to a specific version that you know works correctly.
Using Cocoapods
To get started, first install Cocoapods. You then simply need to create a file in your root project directory (the same directory that contains your .xcodeproj file) called Podfile. Inside, you can specify your target OS, and your dependencies:
platform :ios, '5.0'
pod 'AFNetworking', '0.9.1'
pod 'OHAttributedLabel', '0.1.1'
The example above is targeting iOS 5.0, and pulling in the AFNetworking and OHAttributedLabel projects.
Then, in the Terminal, change to your project directory:
> cd path/to/my/project
And run pod install.
> pod install
This will check out the latest version of your dependencies for you. It will also generate you a .xcworkspace file. From now on, when you work on your project, you must open the .xcworkspace, not the .xcodeproj file.
Inside your new workspace, you'll have your existing Xcode project and a new Pods project - this contains all of your third party libraries. Just build and run your app as normal, and the Pods project will also be built and included.
Some other useful Cocoapods commands:
> pod outdated
Will list all dependencies that have an update available.
> pod search query
Will search all known Pod specs for 'query'. Useful for finding new libraries!
Tutorials
Looks like Tutsplus have a nice tutorial on getting started with Cocoapods
There's a free episode of NSScreencast on Cocoapods
GUIs
I'm afraid I don't know of any GUIs for Cocoapods, but there really aren't many Terminal commands that you need to know. It's worth getting comfortable with the command line, as it's such a useful developer tool.
That said, as far as I know, Appcode (Jetbrains' alternative IDE for Objective-C) is planning on adding Cocoapods support in their next update.
Good luck!
James Frost's answer is an excellent explanation of how to work with Cocoapods and their advantages over submodules.
A few important advantages submodules have over Cocoapods are:
submodules are sub-repos - not only does this mean that git and git GUIs implicitly recognize them and more and more support easily working with them, it also means that your dependencies stay connected the wonderful world their git repos, Cocoapods or not, reside in. This means that you are able to collaborate and test changes from within your project, your project usually being the source of inspiration for elaboration of a dependency.
Unfortunately Cocoapods do not maintain this link, to work on a dependency means to clone it from git, outside of the range of Cocoapods.
Edit: It's worth noting that Cocoapods does allow working on a local pod with the path or local fields or even building your own Spec repo but it still isn't as simple a process.
one less tool dependency - as mentioned in the previous bullet, submodules are a function of git and your using git means they are available to you. Any software's adoption of git implies that they will eventually support either all (important) features of git or all features that cover common use cases. Xcode 5 has brought in a basic support for git and GUIs (which are tool dependencies, it's true, but hopefully just dictate how information is surface, git dictates how it works) like Git Tower make working with sub-repos straightforward.
Cocoapods has come a long way and everyday is taking steps to becoming a stable, indispensable tool. However it hasn't yet gotten a nod from Apple and there isn't any reason why Apple won't release a change to Xcode that breaks Cocoapods. Additionally Cocoapods is dependant on Ruby. Aside, considering how much attention and community has been generated around Cocoapods it would be silly for Apple to ignore it.
It's also worth noting that using one does not lock you out of using the other. It might be a headache or it might be what you need, perhaps using Cocoapods for tiny one class libraries or libraries with complex dependancies and submodules for libraries with that you will be interacting with often.

Resources