Create a new Xcode project in an existing Git repo - ios

I have an iOS app I was writing using React Native until I realized React Native wouldn't fit my needs and I'd need to write the app with Xcode. Because my original project is already in a repo on GitHub, I'd like to use my existing Git repo for the new Xcode project.
I'm new to IDEs and a little scared that if I just move the files over something will get messed up and I won't know how to fix it. Is there a more orthodox way to do this? I've googled this and have come up with lots of advice for adding a new Git repo to an existing Xcode project, but not the other way around.
I appreciate any help I can get!

Simply create a new Xcode project and choose to create it in the same folder on your Mac that is the local copy of the repo.
Deselect the option that says "Create Git repository on my Mac".
This will effectively show up in your local repo as a bunch of files that were added—even an empty Xcode project contains several files.
Xcode will just use the existing repo setup that was already there. So naturally the first step after creating the project would be to commit the Xcode project.
(NB. there is no "rule" that a single repo can not house various projects or "things", although in practice you would often create a fresh repo for the new thing instead of throwing everything together in one)

Related

Removing Swift Packages from Source Control XCode

I recently added some Swift Packages to my Xcode 11.3 project manually by dropping them onto the Project Navigator. This allows me to edit out some errors in the source.
By doing this, Xcode automatically adds these to Source Control.
I can't seem to find any way to remove them from Source Control from within Xcode. I would prefer to retain these as dependencies but commit them to my own source control and ignore master/remote.
Fetch and Refresh Status from Git yields:
This behaviour is instructed by Apple here: Editing a Package Dependency as a Local Package
To add the Swift package as local package to your project:
Check out your package dependency’s source code from its Git
repository.
Open your app’s Xcode project or workspace.
Select the Swift package’s folder in Finder and drag it into the
Project navigator. This action adds your dependency’s Swift package as
a local package to your project.
Make changes to the local package and your app, then verify them by
building and running your app.
When you’re done editing the local package, push your changes to its
remote Git repository.
When the changes have made it into the package’s next release, remove
the local package from your project, and update the package dependency
to the new version.
Step 5 here is broken. I don't have write access to that repo.
Other things I tried.
I've tried deleting Clean, Rebuild and deleting Derived Data
I've tried this SO answer however Blueprint.xcscmblueprint doesn't exist.
The problem you seem to be trying to solve is: You want to make changes to package source files in a maintainable way, and these are not your packages.
Clearly, of itself, that is a complete non-starter. These files don't belong to you, in any sense whatever. And as soon as a new version comes down from the remote repo, your changes will be overwritten anyway.
This sort of thing is always an issue when you rely on third-party code, especially in a dependency architecture like pods or packages. If there's a problem with the code, you can't fix it; it isn't your code.
One option is to create an Issue at GitHub and try to get the owners of the code to fix whatever the problem is.
Another possibility is to try to write "shim" code in your code, such as to fix whatever the issue is by plastering it over somehow.
Alternatively, since this package repo is presumably at GitHub, you can fork the repo. Now it is your package, and you can set up a dependency on that and make changes and push them up to your fork. Of course, the original ("upstream") repo may change, but then you will reconcile those changes with yours as a separate operation.
Still another possibility, of course, is to abandon the notion of package management and dependency entirely and just incorporate the desired source files directly into your project. Now they are yours and you can do with them what you like. (Be careful of copyright issues, of course. You may still have to give credit where credit is due.)
Download the third party library once. Make your changes. Create a patch file. Put the patch file in your source code control. This is followed by lots of manual work when yo want to switch to a different version of the third party library.

Xcode project renamed and now it is lost

I was trying to rename my Xcode project and I followed the apple developer guide and went to View -> Utilities -> Open file inspector and changed the name. Now the initial project only has the pods and the new project created won't run. Is there a way to restore it? I have been working on this project for months and would be devastated if it was lost.
would be devastated if it was lost
That's what version control is for (git).
But if you don't have a git commit to revert to, don't worry; there is a simple solution. Start a new empty project based on one of the built-in app templates and just migrate everything from your old project into that. No actual files have been deleted by whatever you did, so there should be no difficulty about this.

Xcode targets with GIT

Today I created a new target in my iOS app to make a rebrand of the app.
Now I see in Git that it shows some files from the original target(.pbxproj, .xcsheme, .plist) as missing, but that is supposed to happen (I assume).
My question is, what do I do with these files?
Just commit them as missing or is it better to set the files to ignore?
Currently I am working alone on this project but that might change in the future.
Thanks

Integrating CocoaLumberjack into iOS Project via Drag-and-Drop

I'm trying to integrate CocoaLumberjack into my iOS project by dragging-and-dropping the Lumberjack.Xcode file into my project. That works fine, but now my project has 9 new targets. I don't need all of that overhead. So my question is, how do I cut down on the number of targets to just the needed stuff for iOS?
It seems every time I drag over only the mobile project that it is missing needed files. Upon my research, it seems that there are no up-to-date tutorials related to integrating Lumberjack specifically to iOS, which seems like a tool that would be commonly used so that is odd. Being new to all of this, it is troublesome and I would love some help.
Other information: I'm doing a manual installation since Cocoapods is not an option for me. I am following their Installation Guide:
Installation Guide
The very first line in the manual installation guide is
git submodule add git#github.com:CocoaLumberjack/CocoaLumberjack.git
I do not want to add yet another submodule to my project, so I'm dragging and dropping Lumberjack.Xcode into my project.
Before I learned how to use CocoaPods, I used to just clone the repo and copy all of the .h and .m files into my project, ensuring they're added to the correct target.
The only issue you have to make sure to avoid is missing one or more files. Not 100% sure with CocoaLumberjack, but I'd look at just adding everything from here:
https://github.com/CocoaLumberjack/CocoaLumberjack/tree/master/Classes
Instead of adding it as a submodule, you can simply clone the repo and add it to your project. The rest of the instructions remain the same. So replace the line you quoted above with:
git clone git#github.com:CocoaLumberjack/CocoaLumberjack.git
rm -r CocoaLumberjack/.git/
Then follow the rest of the instructions in the install guide.
Instructions from CocoaLumberJack
https://github.com/CocoaLumberjack/CocoaLumberjack/blob/master/Documentation/GettingStarted.md

How do I incorporate a custom control from github to my project and stay up to date

I use a couple of custom controls from github, thus far I've always added source code files as new resources to my project in XCode. But I have now seen this repo getting updated frequently, it made me wonder if I can add source files and get them updated (manually or automatic) when something new is pushed. Sorry it might be a noob question.
This is the repo : BlockAlertsAnd-ActionSheets
Sounds like you want a git submodule.
As far as I know, there's no way to do this within Xcode, so you'd need to do this from the command line.
And if you're comfortable with using git via the Terminal command line, here's a tutorial on how to get this set up.
you can use CocoaPods. and there is a pod for this repo.
it's really useful to manage your dependencies. to get a new version of a pod, you'll need just update your Podfile and run 'pod install'. Check the website, you'll find more info there.

Resources