简体   繁体   English

将现有项目转换为可定制的框架

[英]Converting an existing project into customizable framework

I am a android developer and I needed to create and IOS app.我是一名 android 开发人员,我需要创建和 IOS 应用程序。 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?我是否需要在别处创建一个单独的框架,然后将项目作为 Coca touch 框架导入其中? Am I right??我对吗??
  • How to make it customizable?如何使其可定制? What I meant from Customizable is simple two things.我从可定制的意思是简单的两件事。
    • 1) Colors of Views. 1) 视图的颜色。 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. 2)字符串。 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.注意:我想在框架中转换的项目有两个很多viewController,并且都内置在一个storyboard中。

With regard to how to create a framework, here's how I'd do it:关于如何创建框架,这是我的做法:

  1. Create a workspace:创建工作区: 在此处输入图片说明

  2. 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).通过从 Finder 中将您想要转换为库的项目拖入该工作区(确保它在执行此操作时未在 XCode 中打开)。 Let's call that project FrameworkProj:让我们称该项目为 FrameworkProj:

  3. Create a target for FrameworkProj of type Cocoa Touch Framework:为 Cocoa Touch Framework 类型的 FrameworkProj 创建一个目标: 可可触摸框架

  4. 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。

I think you do not have good idea of the workspace in IOS Xcode.我认为您对 IOS Xcode 中的工作区没有很好的了解。 Since in Android the workspace is dealt in another way.由于在 Android 中,工作区以另一种方式处理。 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.让我告诉你关于 Android 以及你是如何制作库并在 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.假设你在 Android 应用中有一个项目,比如 App1,现在你可以去菜单,你可以添加另一个模块作为库。 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.我们称之为 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.同样,你可以在同一个项目中添加尽可能多的项目/应用程序(在IOS中你可以想到一个工作区),最后,你需要做的就是在所有App1、App2项目中添加你的库项目作为模块依赖创建。

So in IOS, workspace you create at first.所以在 IOS 中,你首先创建的工作区。 And then You create App1, App2 in it.然后在其中创建 App1、App2。 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.你在同一个项目级别(同目录)添加Library(IOS中的Private Framework)然后你可以将Library的依赖添加到你创建的其他项目的Other App1、App2等中。

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.这是我发现的最好的尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM