如何有效地在iOS项目中添加iOS框架 [英] How to add iOS framework in iOS project effectively

查看:81
本文介绍了如何有效地在iOS项目中添加iOS框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近开始进行一个以Swift和Objective-C编写的iOS项目.截至目前,我们有一个整体的仓库.现在,我们专注于创建少量框架,以便我们可以在多个应用程序中重用相同的框架.我想知道您对以下几点的看法.

Recently started work on an iOS project, written in swift and objective-c. As of now, we have a monolithic repo. Now we are focusing on creating few frameworks so that we can reuse same framework across multiple apps. I would like to know your opinion on below points.

  1. 如果在客户端应用程序项目中添加 framework.xcodeproj ,则可以在编写import语句后访问框架的公共实体.我担心的是,每次我由客户端应用程序项目构建时,此 framework.xcodeproj 仍在编译,尽管自上次构建以来未更改,也不依赖于任何其他框架.

  1. If I add framework.xcodeproj in my client app project, I'm able to access the framework's public entities after writing the import statement. My concern is every time I build by client app project, this framework.xcodeproj is also compiling though its has not changed since last build nor it is dependent on any other framework.

如果我通过将框架添加为framework.framework来添加框架并将其输入到嵌入框架中,则可以访问该框架的公共实体.在这种情况下,令人震惊的是,每当我更改框架的代码时,我也需要在客户端应用程序项目中更新框架.

If I add framework by adding it as framework.framework and make its entry into embed framework, I can access the public entities of the framework. What's alarming in this case is that whenever I change the code of framework I need to update the framework in the client app project too.

是否可以在客户端应用程序项目中包含框架,以便我可以访问公共实体,而每次构建客户端应用程序项目时都无法构建框架?

Is there any way to include framework in client app project where I can access the public entities and it does not get build every time I build client app project ?

如果在更新代码时构建框架,那绝对没问题.

It's absolutely fine if framework get's build when its code is updated.

我过去使用过Visual Studio,如果在依赖项目中没有代码更改,那么我可以在不构建依赖项目的情况下构建客户端项目.

I have used Visual studio in past which let me build my client project without building dependent projects if there is not code change in dependent projects.

推荐答案

如果每次构建应用程序时都在构建框架,则取决于框架的类型:

If the framework is build every time you build your app, depends on the type of the framework:

有Cocoa Touch静态库和Cocoa Touch框架.

There are Cocoa Touch Static Libraries and Cocoa Touch Frameworks.

它们始终是开源的,并且会像您的应用程序一样构建.(因此,当您运行应用程序时,并且总是在清理项目后,Xcode有时会对其进行编译.)框架仅支持iOS 8和更高版本,但是您可以在框架中使用Swift和Objective-C.

They are always open-source and will be built just like your app. (So Xcode will sometimes compile it, when you run your app and always after you cleaned the project.) Frameworks only support iOS 8 and newer, but you can use Swift and Objective-C in the framework.

顾名思义,它们是静态的.因此,当您将它们导入到项目中时,它们已经被编译.您可以与其他人共享而不显示他们的代码.请注意,静态库当前不支持Swift.您将不得不在库中使用Objective-C.该应用程序本身仍可以用Swift编写.

As the name says, they are static. So they are already compiled, when you import them to your project. You can share them with others without showing them your code. Note that Static Libraries currently don't support Swift. You will have to use Objective-C within the library. The app itself can still be written in Swift.

如果您不介意使用Objective-C,则静态库似乎很适合您的要求,即该框架只能构建一次.

If you don't mind using Objective-C, Static Libraries seem to fit your requirement, that the framework should only be built once.

但是,由于我喜欢Swift,因此我个人建议您使用框架(如果您不介意使用该框架的其他人可以看到您的代码).我的经验表明,有时构建框架不是什么大问题.

But since I love Swift, I would personally recommend you to use frameworks (if you don't mind that others that use the framework can see your code). My experience showed, that it's not a big problem, that the framework is built sometimes.

AddThis写了一篇不错的博客文章,关于决定使用静态库还是框架.

AddThis wrote a good blog post about deciding whether to use Static Libraries or Frameworks.

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆