Removing Swift Packages from Source Control XCode - ios

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.

Related

Create a new Xcode project in an existing Git repo

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)

How to modify plugins Dart code Flutter?

I am developing a Flutter app, and it uses map_view plugin. I want to add new functionalities to the plugin by modifying the source code. How do I find the actual source code of the plugin in my project after installing it through Flutter?
How plugin is added in Flutter
The dependency for map_view plugin is added to pubspec.yaml as below, then running flutter packages get will add it to the project.
dev_dependecies:
map_view:
Here is step by step of how to modify plugin locally, my plugin named: flutter_abc-0.4.1
Right click on package/plugin's import file name, choose Reveal in Finder
Or hold CMD + Click on that file name to go to that file, then Right click anywhere in the file and choose "Reveal in Finder".
Normally it's located at ~/.pub-cache/hosted/pub.dartlang.org/flutter_abc-0.4.1
Copy whole package folder to your app folder
For easy hijacking files, just copy all to your app folder (same level with pubspec.yaml, not in the lib folder), then renaming version:
For example: flutter_abc-0.4.1-hijacking
Now you can modify whatever you want to fix bug locally.
Modify pubspec.yaml to point to local package
Open your project pubspec.yaml
Change path of dependencies to, for example:
flutter_abc: path: ./flutter_abcd-0.4.1-hijacking/
The most elegant way is to fork a repo, do all changes you need and commit them to your fork of the repo. After that you just need to add forked repo from git as a dependency in pubspec.yaml file.
With the git reposity of the desired plugin here
Clone it.
Make your modification
Submit a pull request.
And done
We usually use packages by importing them in the files where we need them.
To modify a plugin, you need to Ctrl + click on the import line (for e.g. import 'package:dio/dio.dart';) ctrl + clicking on this line will open the source code for this plugin. You can edit the code there.
Remember, the change won't be permanent and if you push your code to git and then clone it later, the changes you've done will be reverted to the original.
So to avoid this, you can just copy all the source code and make a separate dart file and copy and modify all the code there to play safe.
It's worth stating that for quick testing / debugging, you can actually modify the code directly in your .pub-cache, e.g. .pub-cache/hosted/pub.dartlang.org/video_player-2.3.0/lib/video_player.dart. For it to take effect, you must fully restart your app, a hot reload won't work.

Adding an Xcode subproject: Shouldn't all the source files get copied?

I am manually adding the SQLite.swift subproject to my project. As the directions indicated, I copied the .xcodeproj file to my project. This allows me see all the source files (unlike this SO question).
Everything seemed like it was working fine. However, I discovered that the source files of that subproject were not copied to my project. They are still in original location where I downloaded them. Is this by design? What if I want to share my project source code with other people in the future? They won't have the subproject source that is necessary for my project to work.
If I do need to copy the subproject source to my project, then how do I do that?
Add it to your filesystem-structure first. For example by pressing "Show in Finder" on the "Chimee"-project which will lead you to the folder it's located in. Then copy the SQLite-project structure in there.
Afterwards you can then drag&drop the xcodeproj into your project which will then still link to its original path, but as it's now inside your project-structure isn't a problem anymore.
I guess that this is by design, because when you try it via Add files to "YourProject" you can select the Copy items if needed-option but it will still not get copied (only with .xcodeproj-files, it works with all other filetypes)
After doing more research, I now feel that using a dependency manager (like CocoaPods or Carthage) is a better option than manually adding the framework to the project.
This will allow easier updating in the future.
Github source code sharing and App Store submission issues have already been considered.
Using Carthage is not too difficult if you follow this excellent guide: Carthage Tutorial: Getting Started
Notes
Delete the framework files that you manually copied in before installing the framework with Carthage.
I will leave #TMob's answer as accepted for now, but I am no longer pursuing that route.

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