Save packages downloaded by SPM into project GIT using Xcode 11 - ios

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.

Related

xcode 7 svn checkout subdirectory

I'm using Xcode 7.2 and about to checkout subdirectory of a svn repository. For example, if a repository path is svn://mysvn.com/svn/trunk/ios/MyXcodeProject, I want to checkout ONLY 'MyXcodeProject' via Xcode and keep it under version control.
I don't want to checkout all of the subdirectories that I don't care under 'trunk', like android, web, documents etc..
I tried Xcode menu > Source Control > Checkout... by entering the whole repository path(svn://mysvn.com/svn/trunk/ios/MyXcodeProject), however it checked out all of the directories under trunk although those are under version control.
I remember the earlier version of Xcode provided subdirectory checkout but it seems Xcode 7.x~ does not.
Are there any person suffering this problem? Which is the best way I can choose?
I had the same problem, I imported it to to root of the repo, so not under /trunk/myapp but to /myapp.
After that I could checkout the project folder successfully.

XCodeproj empty after cloning from Git

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

Xcode 6 Embedded Binaries

We are building an iOS 8 app on Xcode 6.1 that has the following project structure -
UI (Git Repo 1)
Framework (Git Repo 2)
Git Repo 2 is added as a submodule to Git Repo 1. The framework project is listed as a "Embedded Binary" under the UI project. We have a couple of problems with this -
The embedded binaries' path is specific to a developer's machine and every developer has to update the path after pulling the latest code from the repo.
If the path above is specific to a particular machine how can we build the code on Jenkins?
Is there a better approach to handle the above situation?
If you define your embedded binaries to be Relative to Build Products, then it doesn't matter what the dev's directory structures look like. This enables you to use Jenkins as you wish.
For one of the projects I'm working on, we are using a workspace versus sub-projects since our different libraries are different git repos than the application itself.
Although this is for swift, this link describes a bit about using the Relative To Build Products.
Swift iOS module not being deployed to expected debug directory

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