Create a framework from existing iOS project - ios

I'm new to iOS development and I got this project and need to convert it to a framework so that I can simply add it into different projects. Can someone please help me with this.
I tried different tutorials, but all of them is to create one from new projects

When you want to make a framework, or module, from a project, the first thing you’ll need to do is, if you don’t have one already, make an Xcode project workspace (File > Save as Workspace) . The next step is to add a new framework “project” to your workspace (that could’ve been why you saw some resources telling you to make a new project) with File > New Project and choosing Cocoa Touch framework. When you add it, make sure you pick your workspace under both Add to and Group. Then you will need to migrate in the files that you wanted to be in this module — make sure to choose copy items if needed.
Here’s an article with more specific details on the process if you need it:
https://medium.com/kinandcartacreated/modular-ios-splitting-a-workspace-into-modules-331293f1090

Related

Export files from Xcode project

I currently have an Xcode workspace with an app project and the pod project (as commonly happens). I would like to "export" some of the files containing classes and structs that would be preparatory for a new project that should begin soon. These files are totally separate from each other and should not be exported as a library or framework because that should require to keep everything updated. Instead, I would rather bring these files out of the app project, but keep them into the workspace. Is it possibile? If so, how can I achieve this goal?
When you want to keep your common code and be able to maintain it as one code on both projects then I suggest you still use a framework. It is hard to tell from your question what you mean by "because that should require to keep everything updated" but using a framework within your workspace works awesomely in Xcode and any change you do within framework is instantly reflected in your code. So no extra deployment work is needed at all. To do so you simply do the following:
Create a new project selecting Framework
When creating the project select your workspace from dropdown menu (it is at step where you select project folder location)
In Xcode file navigator in newly created framework project open "Products" directory which should contain (in red) FrameworkName.framework
Open your main project target settings and open General, scroll down to Frameworks, Libraries... and drag that .framework file in this list
That is all. Now you can use your framework in your code. Simply import it in any Swift file you want to.
If at this point you are worried that you need to add import MyFramework into each and every Swift file where you use it then there is a shortcut. You can simply add a new Swift file and use type aliases to avoid this problem:
import MyFramework
typealias Class1 = MyFramework.Class1
typealias Class2 = MyFramework.Class2
typealias Class3 = MyFramework.Class3
Not the cleanest solution but it does the job.
On the other hand if you wish to extract files and use them in a new project but not share the code. So then each of the projects may eventually end up with different implementations of these files then you need to duplicate the files. You can do that easiest with file system by copying source files themselves.
You can then put them into workspace under whatever you want. If you wish that currently none of the projects contain these files you may simply select files in Xcode and uncheck Target Membership for all projects on file settings.

Converting an existing project into customizable framework

I am a android developer and I needed to create and IOS app. So I did and app is ready now. But now I want to make it a Library/Framework. I mean a same code base will be used in different projects per client and they will be able to change the text strings and colors of app. The rest of the business logic will be remain same.
So Simply I have two major question:
How to convert the Project into Framework? Do I need to create a separate framework elsewhere and then import the project into it as Coca touch Framework? Am I right??
How to make it customizable? What I meant from Customizable is simple two things.
1) Colors of Views. I have two many views. I want A separate file of colors so that I can change color in it and it reflects changes in whole application
2) String. I want to change the text string so that it can be changed in all over the projects.
Please tell me how can I achieve these things. Specially point number two is my main concern.
Note: The project that I want to convert in framework has two many viewControllers and all are built in one storyboard.
With regard to how to create a framework, here's how I'd do it:
Create a workspace:
Bring the project you want to turn into a library into that workspace by dragging it in from the Finder (make sure it's not open in XCode when you do this). Let's call that project FrameworkProj:
Create a target for FrameworkProj of type Cocoa Touch Framework:
Create a second project, which we'll call SampleProjWhichUsesFramework, and import the framework into it.
As for your question of IB elements being settable via the framework, simply make sure you have IBOutlets for those elements that are marked public, and they will be available to SampleProjWhichUsesFramework as properties of your framework.
I think you do not have good idea of the workspace in IOS Xcode. Since in Android the workspace is dealt in another way. But there is a slight difference.
Lets me just tell you about Android and how do you made the Library and add several projects in Android studio. let say you have a Project in Android App, say App1, now you can go to menu and you can add another module as Library. That is fine and easy for you.
Now you can create another project like this, GO to new menu, here you can select New Module and then from templates you can select Phone and Table Module. let's call it App2.
Similarly you can add as many projects/app in the same project (in IOS you can think of a Workspace), and in the end, All you need to do is adding Your library project as a module dependency in All App1, App2 projects you created.
So in IOS, workspace you create at first. And then You create App1, App2 in it. You add Library (Private Framework in IOS) in same project level (same directory) Then You can add the dependency of Library into Other App1, App2 and so on other projects you created.
In this way, your codebase will remain the same for others.
You can find the whole tutorial here. It is the best I have found just give it a try.

Do I need to add my framework to project again and again after editing ios?

I have my own framework which I've made. I use this framework in another project I made. That is, after building my framework, Dragged the Product, .framework to Embedded Binaries of project.
However, I've to continuously make changes to the framework. So the process of dragging and dropping again and again is a lot of work. How to conquer this ?
Can someone tell the exact steps even if it means including the project as well ?
Copy the framework Project to your project folder.
Open your Project in xcode.
Right click on the Project File on left side of xcode and click on option "Add file to Project Name" and then select the framework project here.
Delete the Product .framework available in the embedded libraries and add the framework product properly.
So your goal is to 'deploy' changes made to .framework to all the projects you've already embedded it in previously. Here is one approach to it.
Create [myFramework]Targets.txt file where you'll be putting all the locations (directories) of your framework in different projects, line by line. It will have something like this:
~/Path/to/project/A/Frameworks
~/Path/to/project/B/Frameworks
~/Path/to/project/C/Frameworks
Create deploy_framework.sh file with script that will replace your framework everywhere you need. I'm definitely not the one you can call a Bash expert, by here is what it probably looks like:
for destination in $(<[myFramework]Targets.txt); do /bin/cp -rf /Path/to/updated/[myFramework].framework "$destination"; done
Now, whenever you're done with your framework changes, just run deploy_framework.sh from Terminal. Assuming your Xcode projects have existing reference to .framework and you didn't change its name, it should work.
NOTE: You might still need to do Clean+Build for your projects to compile with updated framework. I believe you can also tweak project settings to 'cache' builds less aggressively.
Let me know if it works for you, we might need to adjust script a bit, since I never tested it.

Duplicating a project and changing its name

I was creating a new project that is a copy of another project. The thing is that when I want to rename the project, some connection problems appear when I want to execute my app. Can someone tell me a good way to replace all the names of the old project? The classe names are the same in the new one, so I don't have to change them.
Thanks!
I have done this recently and it was a straightforward process.
I suggest you start again. Make a copy of the project then click twice slowly on the project name in the project navigator. You can then rename the project.
Xcode then suggests which files/resources to change - you can accept all changes or amend if you like.
Once complete your project will build and run with no problems.

XCode - Workspaces

i'm developing a framework and i would like to know if there is a method for share the code across multiple project. Example : i have my workspace with my framework project and a test application project for the fw; then, i have another project of an app and i need to use the framework, but i want to link the framework so that when i modify the original code in workspace even the code in the project is updated without import every time the .framework file.
Is it possible?
If not, how can i do to share code across projects?
Thanks
Yes, this can easily be done by importing files from the other project. You could create a group called external, right click and choose "add files". Make sure the option "copy items into destination group`s folder" is unchecked.
If you now change the files in the other project, the changes will be reflected in the dependent one.

Resources