I have a single class with all handy code snippets I use all the time in every projects. What I would like to do is keep that single class in sync with other projects in Xcode.
Example:
I have two projects both with the "general class". I open Project A and add some code to the "general class". Then when I open project B it will be there too.
Is this possible in anyway? Can this be done with Git?
I had the same issue, I used the solution below to solve it
Copied all classes to be shared in a folder out of any project.
Added that folder into different projects (using git) by right-clicking in the project navigator and choosing "Add Files to " without creating a local copy.
For example I have the following folders:
DataAccessLayer- contains C++ class to acces to the DB
BusinessLayer- All C++ core business classes of my applications
iOS- All iOS interface classes and a wrapper for C++ classes
XOS- All iOS interface classes and a wrapper for C++ classes
In the last 2 folders are projects which use same clases. When I edit a file from a project the change is reflected in the other projects
I hope this will help you
You can use cocoapods for that. Create podspec, then add it into Podfile of all projects as local dependency by "pod MyLib, :path => '~/path/to' ". See more https://guides.cocoapods.org/syntax/podspec.html#specification
Git submodules are another clean way of doing this. The submodule will be seen as a directory in multiple projects, and you can push changes to it as it is also a git repository. See https://chrisjean.com/git-submodules-adding-using-removing-and-updating/ CocoaPods are another good option, but require you learning about how to make CocoaPods.
Related
I have a set of utility classes that I reuse in several xcode projects.
I want to include the utility classes in every project.
I currently do this by adding inside every xcode project a group and dropping there the files from the file system.
This way, they are included in the compilation.
But every time I do filename changes in the utility classes (e.g. add/rename/delete a file) I have to go through all the projects and reflect the change there.
Some notes:
The projects are irrelevant, i.e. not different products from a suite of products. So I cannot use an all products project and do the separation at the targets level for each of the products.
When I do changes in a utility class from one of the projects, the changes should be reflected in all other projects.
the utility classes are already on a repo of their own.
I prefer not to make copies of the files of the utility classes inside every project
I do not want to do the trip of creating a framework that will then be used by every project. Not all classes are used by every project. I just want to have them compiled as a source files.
As a test, I made a project containing the utility classes and no target, added the project as a child of one of my projects.
I.e. instead of having the yellow folder icon of the file group, I have a project icon containing the files.
The compilation does not seem to pick these files.
Maybe a cmakelists.txt file could serve this purpose? I.e. give to xcode an additional list of files to include in the compilation?
For the Windows's edition of my projects, I use Microsoft's Visual Studio "shared items" project which accomplishes exactly all these requirements.
What is your advice for xcode?
Thanks!
Similar to:
Sharing classes between projects in xcode/objective-c
Sharing classes between Xcode projects
I have two projects. Project A and Project B.
Project A is in Objective C, while the other is in Swift 3.0.
Project A is already stable, however a new functionality will be added.
Project A is already in a workspace.
Here's where Project B comes into place.
In Project B, I'm developing a library that will be used by Project A.
Project B is using external libraries such as Alamofire.
I want Project A to use Project B. What I've tried is to combine these two into Project A's workspace. I placed Project B inside Project A's workspace.
However, Project B's external libraries were not included in the transfer.
I'm using Cocoapods in both projects.
Or do I have to re-add the external libraries?
I just managed to get a simpler version of your problem working. I had one existing Cocoapods workspace, that built a framework, that I wanted to combine with another project. I created a new workspace, and then added three projects to it, and then embedded the framework and its dependencies. Let me describe in more detail.
The three projects were as follows:
My framework (MyFramework)
My framework's dependencies, managed by Cocoa pods (Pods)
My New App (MyApp)
The first two, MyFramework and Pods, were from the existing workspace. Got that?
When I created a new workspace, there were basically two steps. First I had to add the above three projects. Then, in the General tab of the MyApp project (in my new workspace), I had to add MyFramework to the "Embed Frameworks" section. That got everything wired up.
As it turned out, in my particular case, I got a crash at runtime which complained about a missing bundle. That bundle was actually a product of the Pods project. I found that bundle on my filesystem and then dragged it into my workspace (which added it to the "Copy Bundle Resources" section of my General tab for MyApp). That got everything working.
In short, I didn't combine two workspaces. Instead, I dismantled the first workspace (in a manner of speaking) and added its parts to a new workspace, which included my new app.
I hope the above gives you a hint as to how to proceed. Good luck!
How can I include a project (is standalone) into my project and launch it from within my own app? What are the requiered steps so that my current project recognizes all the sourcecode from the other project?
If you are intending to run an application unmodified from another application, you can't do this. iOS expects you to have one application executable with one entry point and one app delegate.
If you have a library in source form that you would like to include in your project, you can simply drag the files into Xcode while your project is open.
If you drag an Xcode project file into the project navigator sidebar it will be added to the project setup.
You will need to configure import paths and other things in order to access code though.
If you are trying to use 3rd party libraries, I strongly recommend having a look at CocoaPods. It's really easy to set up and manages dependencies with all of their build settings for you.
I'm quite new to QtCreator, so perhaps I left my heart in eclipse-ville, but I can't for the life of me understand how I should be setting up a project hierarchy in QtCreator. I understand there is an option to create a kind of root project and then from there add sub-projects to it, which makes sense but it leaves me wondering whether or not this is necessary at the time of creating the project, e.g. can I just create a library in one project and reference it later by another project?
I've tried setting up a blanket type of project by creating a new subdirs project and then adding the main program as a subproject, but then how should I add my library project?
Ideally, I'd like to create one project as the main application and reference another project as a library. Help?
The documentation of Qt Creator contains two sections that may help you find the answers to your questions:
Adding Subprojects to Projects
Adding Libraries to Projects
EDIT:
You can find a really simple sample project here: QtSymbianDllExample. "It is intended to demonstrate how to create and use a DLL with Qt on the Symbian platform". It is a sample for Symbian development but that is irrelevant now, I do not have a Symbian phone. What is important is that it contains a root project (QtSymbianDllExample\qtssymbiandllexample.pro) and two subprojects (QtSymbianDllExample\qtenginedll\qtenginedll.pro, QtSymbianDllExample\testui_simpledllengine\testui_simpledllengine.pro) which you can examine and compare to you projects. I have checked that I can build the root project by doing the following steps:
Download and install the Windows Offline Installer from http://www.qt.io/download/
Download and extract QtSymbianDllExample.zip
Run Qt Creator
File / Open File or Project... Select qtssymbiandllexample.pro
Build / Run qmake
Build / Build project "qtsymbiandllexample"
I have many projects that use a bunch of exact same class.
Is there a way to add a script to Xcode, so, each time i compile, he go to a network folder and update is files from there... If newer. (i do this step manually, but could be great to automate it)
Thanks
You could add a "run script" build phase to copy over files before compiling if that's really what you want to do. That would catch updates for you but I don't think it would help you if new files are added (though copying them into a location your project has a folder reference rather than a group pointing to might work).
That said I think there's a better solution. It sounds like you're reinventing a process for managing project dependencies when you could use existing tools. I would publish those shared classes as a library and add it to each project using CocoaPods and a reference to the library's git repository. That way you just need to run a pod install to get the latest version of your library. A good dependency manager gives you a clear understanding of which version of your dependencies you're currently using, control over when to update them, handles installing dependencies of your dependencies, and will avoid link errors from multiple static libraries attempting to each include a copy of the same common dependency.