简体   繁体   English

带有嵌入库的 Cocoa Touch Framework Swift

[英]Cocoa Touch Framework Swift with embed libraries

I am working on a suite of applications that contain common modules.我正在开发一套包含通用模块的应用程序。 I want to store the common modules in a Cocoa Touch Framework.我想将通用模块存储在 Cocoa Touch Framework 中。 This framework may also contain the libraries and Alamofire and SwiftyJSON because they are widely used in the modules.这个框架也可能包含库和 Alamofire 和 SwiftyJSON,因为它们在模块中被广泛使用。 Currently, despite the many tutorials, articles, etc. read on the internet, I cannot get a stable solution.目前,尽管在互联网上阅读了许多教程、文章等,但我无法得到稳定的解决方案。

  • Is it possible to integrate the frameworks Alamofire and SwiftyJSON within the framework custom or is it better to integrate them in the different projects consuming the framework (they will also need individually) ?是否可以将 Alamofire 和 SwiftyJSON 框架集成到框架自定义中,还是将它们集成到使用该框架的不同项目中更好(它们也将单独需要)?
  • Is it possible to generate a framework running on the simulator and on the phone (whatever methods: subproject or not, dynamic or static library, fat library) ?是否可以生成在模拟器和手机上运行的框架(无论是哪种方法:子项目与否,动态或静态库,胖库)?

You can absolutely do this.你绝对可以做到这一点。 You currently have three options for setting this up for development and two options for deployment.您目前有三个选项用于设置开发和两个部署选项。


Development发展

Git Submodules Git 子模块

Git submodules are a great way to bring additional libraries into your project's repository to embed in your project. Git 子模块是将其他库引入项目存储库以嵌入项目的好方法。 All you need to do is add the submodule, then drag the Xcode project of that library into your Xcode project so it's nested inside your project.您需要做的就是添加子模块,然后将该库的 Xcode 项目拖到您的 Xcode 项目中,使其嵌套在您的项目中。 Then you need to add the framework as a link target to your library.然后您需要将框架作为链接目标添加到您的库中。

Carthage迦太基

Carthage also supports git submodules through the --use-submodules flag. Carthage还通过--use-submodules标志支持 git 子--use-submodules All you need to do is install carthage through homebrew, then create a Cartfile that adds Alamofire and SwiftyJSON using the following command.所有你需要做的是安装通过自制迦太基,然后创建一个Cartfile ,增加了Alamofire和SwiftyJSON使用下面的命令。

carthage update --use-submodules

CocoaPods可可豆

CocoaPods is a dependency management system that allows you to easily pull in and deploy different versions of a given library. CocoaPods是一个依赖管理系统,它允许您轻松地引入和部署给定库的不同版本。 Since both Alamofire and SwiftyJSON support CocoaPods, you could create a Podfile , and run pod install to pull the pods into your library.由于AlamofireSwiftyJSON 都支持 CocoaPods,您可以创建一个Podfile ,然后运行pod install将 Pod 拉入您的库中。 I would not recommend this though as this is a pretty heavy weight approach.我不会推荐这个,因为这是一个非常重的方法。 Instead, I would recommend using either Git Submodules or Carthage for development.相反,我建议使用Git SubmodulesCarthage进行开发。


Deployment部署

Deployment is a MUCH different situation.部署是一个非常不同的情况。 Currently, there are two fairly robust deployment mechanisms for iOS and OSX that are in wide use in the OSS community (including Alamofire and Carthage).目前,在 OSS 社区(包括 Alamofire 和 Carthage)中广泛使用的 iOS 和 OSX 有两种相当健壮的部署机制。

Carthage迦太基

If you imported your git submodules using Carthage, then you may already be completely supporting Carthage deployments.如果您使用 Carthage 导入了 git 子模块,那么您可能已经完全支持 Carthage 部署。 It depends on whether you used a Cartfile.private file to pull in your dependencies.这取决于您是否使用Cartfile.private文件来拉入您的依赖项。 Given what you're trying to do, I doubt that you would use a private Cartfile and would instead use the public one.鉴于您正在尝试做的事情,我怀疑您是否会使用私有 Cartfile 而会使用公共 Cartfile。 This means that you should be good to go right out of the box.这意味着您应该开箱即用。 Awesome!惊人的!

CocoaPods可可豆

CocoaPods is much different than Carthage and has some big advantages over Carthage, at a cost. CocoaPods 与 Carthage 有很大不同,并且比 Carthage 有一些很大的优势,但要付出代价。 You need to create a podspec file and push that into a public or private spec repo.您需要创建一个 podspec 文件并将其推送到公共或私有规范存储库中。 Then anyone can pull your pod into their project using a Podfile.然后任何人都可以使用 Podfile 将您的 pod 拉入他们的项目。


Summary概括

As you can see, there are MANY options here.如您所见,这里有很多选择。 I would highly recommend using Carthage to pull in your git submodules, then supporting both Carthage and CocoaPods for deployment.我强烈建议使用 Carthage 来拉入你的 git 子模块,然后支持 Carthage 和 CocoaPods 进行部署。 I know that's a lot of effort though, so you may want to focus on one or the other.我知道这需要付出很多努力,因此您可能希望专注于其中一个。 Sorry for the massive amount of links and information, but you question leads me to believe that you would greatly benefit from all these various sources.抱歉提供了大量的链接和信息,但您的问题让我相信您将从所有这些不同的来源中受益匪浅。

Hopefully that helps get you on your way to becoming a dependency development and deployment ninja.希望这有助于您成为依赖开发和部署忍者。

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

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