如何在不暴露源代码的情况下分发Swift库?

编程入门 行业动态 更新时间:2024-10-27 18:33:44
本文介绍了如何在不暴露源代码的情况下分发Swift库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试的第一件事是创建一个静态库但稍后我发现它还没有得到支持。 Apple Xcode Beta 4发行说明:

The first thing I tried is to create a static library but later I found out that it's not supported yet. Apple Xcode Beta 4 Release Notes:

Xcode不支持构建包含Swift 代码的静态库。 (17181019)

Xcode does not support building static libraries that include Swift code. (17181019)

我希望Apple能够在下一个Beta版本或GA版本中添加它,但我读了关注他们的博客:

I was hoping that Apple will be able to add this in the next Beta release or the GA version but I read the following on their blog:

虽然确保了你的应用程序的运行时兼容性,但Swift语言本身将继续发展,二进制接口也会发生变化。为了安全起见,应用程序的所有组件应使用相同版本的Xcode 和Swift编译器构建,以确保它们一起工作。

While your app’s runtime compatibility is ensured, the Swift language itself will continue to evolve, and the binary interface will also change. To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.

这意味着需要仔细管理框架。例如,如果您的项目使用框架与嵌入的扩展共享代码,您将需要一起构建框架,应用程序和扩展。 依赖于使用Swift的二进制框架是危险的 - 特别是来自第三方。随着Swift的改变,那些框架将与你的应用程序的其余部分不兼容。当二进制接口在一年或两年内稳定时,Swift运行时将成为主机操作系统的一部分,并且此限制将不再存在。

This means that frameworks need to be managed carefully. For instance, if your project uses frameworks to share code with an embedded extension, you will want to build the frameworks, app, and extensions together. It would be dangerous to rely upon binary frameworks that use Swift — especially from third parties. As Swift changes, those frameworks will be incompatible with the rest of your app. When the binary interface stabilizes in a year or two, the Swift runtime will become part of the host OS and this limitation will no longer exist.

对于我为其他开发人员编写组件以供其使用并包含在他们的应用程序中的人来说,这个消息真的令人担忧。这是否意味着我必须分发源代码或等待两年?有没有其他方法来分发库而不暴露代码(公司政策)?

The news is really alarming for me a person who writes components for other developers to use and include in their apps. Is this means that I have to distribute the source code or wait for two years?. Is there any other way to distribute the library without exposing the code (company policy)?

更新:

此时Swift代码混淆是一个选项吗?

Is Swift code obfuscation an option at this point ?

推荐答案

Swift现在是测试版,即使对于1.0,Apple也非常清楚他们是在一个受限制的功能集之后 - 更好地完成少量事情而不是尝试做所有事情。

Swift is beta now, and even for 1.0 Apple has been pretty clear they're after a restricted feature set -- better to do a small number of things well than to try to do everything.

所以现在,没有办法分发二进制静态库。据推测,在Swift 1.0之后某个时候会发生变化。现在,您可以:

So for now, there's no way to distribute binary static libraries. Presumably that'll change sometime after Swift 1.0. For now, you can:

  • 分发来源
  • 发送二进制框架(而不是库)如果你对ABI很脆弱是好的
  • 使用ObjC代码库
  • Distribute source
  • Ship a binary framework (instead of a library) if you're okay with the ABI being fragile
  • Use ObjC for library code

您也可以随时组合方法:例如,在ObjC中实现库的关键(秘密)细节,并运送Swift源代码,将其包装在一个漂亮的Swift API中。

You can always combine approaches, too: e.g., implement the critical (secret) details of your library in ObjC, and ship Swift source that wraps it in a nice Swift API.

用一种非常容易改变的语言编写的混淆代码听起来就像维护噩梦的秘诀一样。

Obfuscating code written in a language that's very much subject to change sounds like a recipe for a maintenance nightmare.

更多推荐

如何在不暴露源代码的情况下分发Swift库?

本文发布于:2023-11-23 09:15:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:源代码   情况下   如何在   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!