XCodeproj empty after cloning from Git - ios

I have an Swift project that utilizes two libraries: the SQLite and SwiftCSV project. They can be found on: https://github.com/stephencelis/SQLite.swift and https://github.com/naoty/SwiftCSV respectively. I followed the instructions on each respective Github README to incorporate the projects into my project which works fine, but when I push my project to Github and I have another teammate of mine clone the project, the SwiftCSV and SQLite projects turn up empty so my teammate has to re-add them into his project. I have been trying to google different responses but maybe I am looking for the wrong keywords. Any ideas on how to fix this?

You should (and may be) adding the above projects to your repo as submodules (if not, read up on them).
If you used submodules, they are not automatically checked out when you clone a repository. You can, however, use clone's --recursive flag to ensure submodules are checked out when someone first clones your project:
git clone --recursive git#github.com:your/project.git
If the project has already been cloned, one can check out the submodules by running the following incantation from within their project directory:
git submodule update --init
Note: Xcode is usually smart about letting you check out submodules from within Xcode itself. Check the Source Control menu and see if SQLite.swift or SwiftCSV show up under Working Copies.
If you merely downloaded the projects and dragged them into your Xcode project (rather than use submodules, as instructed above), they'll likely be referencing directories outside of your project. Make sure you move them to your project's directory before dragging them into your Xcode project. If you don't, the projects will appear red/unavailable on subsequent clones.

usually, xcodeproj is in gitignore, please remove it from .gitignore file

Related

Save packages downloaded by SPM into project GIT using Xcode 11

I started using new Xcode 11 which integrates SPM.
I added first dependency to my project:
but detected that files are not fetched into my project folder but into Xcode's cache:
I would like to commit all my dependencies files into my main project repository so my question is:
Is it possible to change location of fetched packages via SPM using Xcode 11?
It's somewhat possible, although the solution isn't necessarily a good or great practice, so I can't recommend.
Set the DerivedData in workspace settings to be relative to the workspace.
Add gitignore rules such that the workspace/WORKSPACE_NAME_DIR/SourcePackages/checkouts and related files are includes. Maybe best to ensure repositories directory is not included.
Add a Run Script phase to remove .git and .gitignore files in the checkouts directory.
Obviously, this is fragile largely through fighting the way SPM works. The workspace settings are per person so it's not great in teams.
SwiftPM integration has been setup to prevent this. It clones the files into a DerivedData/ProjectName-[RandomStuff]. You should commit your Package.resolved into the repo to ensure that you get the same version of each dependency across clones of the project.

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.)

Xcode bot: cloning multiple repositories before build

I have three repositories for my current project. They contain some shareable core functionality and individualized components:
MainApp.git
Components.git
Controls.git
The xcworkspace lies in MainApp.git and links to its own xcodeproj file as well as the other xcodeprojs in the two other repositories.
When creating a bot in Xcode server, there's only the option to select one repository for cloning. This lets the build fail eventually, since it cannot find any resources needed from the Components.git and Controls.git.
How can I achieve a working build with my workspace configuration?
You could:
1) Add all the code to the main repo (I highly advise against it)
2) Use a dependency manager such as Cocoapods, where you would have to create podspecs for your dependencies. If they are open-source great they are probably already in GitHub in Specs. Integration between Xcode bots and Cocoapods is kind of broken right now. You could have a pre-build script running the command:
pod install
Amongst other things. See here
3) Use git submodules. They can give you some headaches but they usually do the job when it comes to managing enterprise dependencies. Once again, unfortunately, they are completely broken in Xcode bots:
Xcode bots with git submodules
Problems with Xcode Bots
The list is large, a mere search on twitter for problems related with git/cocoapods and Xcode bots will show you how frustrating it can be.
My personal opinion, if it is a small project and you want to see what Apple's been up to, Xcode bots are great, also the built-in integration inside the IDE is amazing and something to look for in the upcoming iterations.
However, if the project is complex, with some dependencies, maybe UI Automation, integration with Testflight/HockeyApp, etc, I would go with either Jenkins or Travis CI.
Stick with something that has a great community, years of development, plugins..
I was looking for this answer myself, but was not satisfied with the suggestions.
Turns out, it is possible to do everything inside Xcode with just a little helping from the Terminal.
I detailed it here: http://swiftrien.blogspot.com/2016/04/xcode-server-and-multiple-repositories.html
But will summarise here.
1) Create a workspace directory. None of the projects to-be in the workspace should be in this directory (or any of its subdirectories).
2) Using Xcode, create the workspace. You can add the projects now.
3) Exit Xcode.
4) In Terminal go to the workspace directory and do "$ git init"
5) Add a ".gitignore" file with ".DS_Store" and "xcuserdata".
6) Add the files with "$ git add ."
7) Commit the files with '$ git commit -m "Initial commit"'
8) Exit Terminal, start Xcode and open the workspace
9) Use the "Source Control" menu to verify that you now have a git repo for the workspace.
10) Use the "Source Control" menu to add a remote repo on the server.
11) For all projects, use the "Source Control -> Configure ..." menu to tell Xcode that that repo is necessary to include in the checkout.
You will need to create new bots or upgrade the old ones.
Good luck.

Issues Using GIT with Xcode projects

I know git and use it to manage a lot of my Repos on other projects. However I run into issues when it comes to xcode projects.
I start a project on Machine 'A' - when I push up to a repo and pull to let say machine 'B' I always receive compiling errors. Normally the errors have to do with files not being found. Literally "no such file or directory" followed by a path.
I'm working with the same version of Xcode on both mac's A and B. I also use the threetwenty framework.
When I zip the project up and send via email - the same results occur.
Many times these files that xcode can't find and that fail the build, are media files, like a image or video. Sometimes I see the three20 framework too.
My question is - how in xcode should I set a project up to play nice with git and or code sharing in general. Let me know if you need more information, I know the above is a little vague.
The first thing I always do is set up the .gitignore file before adding any other files from the project. Problems can occur when loading project settings for two different machines that may have the same User account name. You have to make sure some settings aren't added to the repo whilst others are.
I set up my .gitignore by adding the following:
.DS_Store
*/.DS_Store
*.swp
*~.nib
build/
*.pbxuser
*.perspective
*.perspectivev3
*.mode1v3
*.mode2v3
Documentation/Generated
doxygenWarnings.txt
*.xcodeproj/xcuserdata/*.xcuserdatad
*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
*/*.xcodeproj/xcuserdata/*.xcuserdatad
*/*.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad
If you create the repos from scratch or run git rm --cached <filethatshouldbeignore> to each file that should be ignored and then commit, see if the problem still occurs.
Problems will occur in the .pbxproj file, so make sure all conflicts are corrected too.
Regarding files that cannot be found, remember to import the libraries etc. into the project folders and reference them from there. Apple's own iOS libraries should be fine, but others won't be. For example, in your project folder, copy your images from there and reference them only within the project folder.

Resources