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.
我是一个Android开发人员,我需要创建和IOS应用程序。所以我做了,应用程序现在就准备好了。但现在我想把它变成一个图书馆/框架。我的意思是每个客户端在不同的项目中使用相同的代码库,他们将能够更改应用程序的文本字符串和颜色。其余的业务逻辑将保持不变。
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.
1)视图的颜色。我有两个很多观点。我想要一个单独的颜色文件,这样我就可以改变它的颜色,它反映了整个应用程序的变化
2)字符串。我想更改文本字符串,以便可以在所有项目中更改它。
如何将项目转换为框架?我是否需要在其他地方创建单独的框架,然后将项目作为Coca touch Framework导入其中?我对吗??
如何使其可定制?我对Customizable的意思是简单的两件事。 1)视图的颜色。我有两个很多观点。我想要一个单独的颜色文件,以便我可以更改它的颜色,它反映了整个应用程序的变化2)字符串。我想更改文本字符串,以便可以在所有项目中更改它。
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.
注意:我想在框架中转换的项目有两个viewControllers,并且都在一个故事板中构建。
2 个解决方案
#1
3
With regard to how to create a framework, here's how I'd do it:
关于如何创建框架,这是我如何做到的:
-
创建工作区:
-
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:
通过从Finder中拖入项目,将要转换为库的项目放入该工作区(确保在执行此操作时不在XCode中打开)。我们称之为项目FrameworkProj:
-
Create a target for FrameworkProj of type Cocoa Touch Framework:
为Cocoa Touch Framework类型的FrameworkProj创建一个目标:
-
Create a second project, which we'll call SampleProjWhichUsesFramework, and import the framework into it.
创建第二个项目,我们将其称为SampleProjWhichUsesFramework,并将框架导入其中。
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.
至于你可以通过框架设置IB元素的问题,只需确保你有那些标记为公共元素的IBOutlets,它们将作为框架的属性提供给SampleProjWhichUsesFramework。
#2
3
I think you have not a good concept of workspace in IOS xcode. Since in Android the workspace is dealt in other way. But there is a slightly a difference.
我认为你在IOS xcode中没有一个好的工作空间概念。因为在Android中,工作空间以其他方式处理。但是略有不同。
Lets me just tell you about Android and how do you made Library and add several projects in Android studio. let say you have a Project in Android App, lets say it 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 tamplates you can select Phone and Table Module. lets call it App2.
让我告诉你关于Android的问题,你如何制作图书馆并在Android工作室中添加几个项目。假设您在Android应用程序中有一个项目,让我们说它是App1,现在您可以转到菜单,然后您可以添加另一个模块作为库。这对你很好,很容易。现在你可以创建这样的另一个项目,转到新菜单,在这里你可以选择New Module,然后从tamplates你可以选择Phone和Table Module。我们称之为App2。
Similalrly you can add as much projects/app in a 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.
同样,您可以在同一个项目中添加尽可能多的项目/应用程序(在IOS中您可以想到一个工作区),最后您需要做的就是将您的库项目添加为您创建的所有App1,App2项目中的模块依赖项。
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 dependency of Library into Other App1 , App2 and so on other projects you created.
所以在IOS中,您首先创建工作空间。然后你在其中创建App1,App2。您在同一项目级别(同一目录)中添加库(IOS中的私有框架)然后您可以将库的依赖项添加到其他App1,App2等您创建的其他项目中。
In this way your code base will remain same for others.
通过这种方式,您的代码库将对其他人保持相同。
You can find whole tutorial here. It is the best I have found just give it a try.
你可以在这里找到整个教程。这是我发现的最好的尝试。
#1
3
With regard to how to create a framework, here's how I'd do it:
关于如何创建框架,这是我如何做到的:
-
创建工作区:
-
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:
通过从Finder中拖入项目,将要转换为库的项目放入该工作区(确保在执行此操作时不在XCode中打开)。我们称之为项目FrameworkProj:
-
Create a target for FrameworkProj of type Cocoa Touch Framework:
为Cocoa Touch Framework类型的FrameworkProj创建一个目标:
-
Create a second project, which we'll call SampleProjWhichUsesFramework, and import the framework into it.
创建第二个项目,我们将其称为SampleProjWhichUsesFramework,并将框架导入其中。
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.
至于你可以通过框架设置IB元素的问题,只需确保你有那些标记为公共元素的IBOutlets,它们将作为框架的属性提供给SampleProjWhichUsesFramework。
#2
3
I think you have not a good concept of workspace in IOS xcode. Since in Android the workspace is dealt in other way. But there is a slightly a difference.
我认为你在IOS xcode中没有一个好的工作空间概念。因为在Android中,工作空间以其他方式处理。但是略有不同。
Lets me just tell you about Android and how do you made Library and add several projects in Android studio. let say you have a Project in Android App, lets say it 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 tamplates you can select Phone and Table Module. lets call it App2.
让我告诉你关于Android的问题,你如何制作图书馆并在Android工作室中添加几个项目。假设您在Android应用程序中有一个项目,让我们说它是App1,现在您可以转到菜单,然后您可以添加另一个模块作为库。这对你很好,很容易。现在你可以创建这样的另一个项目,转到新菜单,在这里你可以选择New Module,然后从tamplates你可以选择Phone和Table Module。我们称之为App2。
Similalrly you can add as much projects/app in a 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.
同样,您可以在同一个项目中添加尽可能多的项目/应用程序(在IOS中您可以想到一个工作区),最后您需要做的就是将您的库项目添加为您创建的所有App1,App2项目中的模块依赖项。
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 dependency of Library into Other App1 , App2 and so on other projects you created.
所以在IOS中,您首先创建工作空间。然后你在其中创建App1,App2。您在同一项目级别(同一目录)中添加库(IOS中的私有框架)然后您可以将库的依赖项添加到其他App1,App2等您创建的其他项目中。
In this way your code base will remain same for others.
通过这种方式,您的代码库将对其他人保持相同。
You can find whole tutorial here. It is the best I have found just give it a try.
你可以在这里找到整个教程。这是我发现的最好的尝试。