即将(Java)库移植到 Objective-C:方法论?

发布于 2024-09-29 13:58:44 字数 246 浏览 6 评论 0原文

我是一名 iOS 开发人员,我发现了一个很棒的库,可以为我处理各种与天文学相关的计算。问题是它是用Java 编写的。虽然我对接近 Java 的语言有足够的经验,但我无法在 iOS 上运行 Java。

我想移植它,但因为我以前从未移植过任何东西。就像我说的,我认为语言不是问题。这是一个相当简单的库,主要涉及日期对象和数学。

我正在尝试找出进行移植的最佳方法。我是从每个类的核心方法/函数开始,还是可以在每个文件中逐行进行操作,直到翻译完所有内容?

I am an iOS developer and I found a great library that handles all kinds of astronomy related calculations for me. The problem is that it's written in Java. Although I have enough experience with languages close to Java, I can't run Java on iOS.

I'd like to port it, but being that I've never ported anything before. Like I said, I don't think language will be the issue. It's a fairly simple library, involving mostly Date objects and math.

I'm trying to figure out the best way to do go about porting. Do I start with the core methods/functions of each class, or can I just go line by line in each file until I have translated everything?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光的暖冬 2024-10-06 13:58:44

随心所欲地开始。一般来说,您需要从核心附近开始,然后逐步解决。只需记住这三个步骤:

  1. 让它工作
  2. 让它正确
  3. 让它快速/干净

所以不要担心让它看起来漂亮或立即发生任何事情,只需让它按照需要的方式工作,测试它即可。然后看看如果可能的话可以在哪里重构等等。

Just start wherever you please. Generally, you'll want to start near the core, and work your way out. Just remember these three steps:

  1. Make it work
  2. Make it right
  3. Make it fast/clean

So don't worry about getting it looking pretty or anything right off the hop, just get it working how it needs to, test it. Then look at where you can refactor if possible, etc.

静水深流 2024-10-06 13:58:44

由于这似乎是一个函数库,因此它不依赖于任何特定于平台的函数。

移植这个应该非常简单。您可以按功能移植功能,也许可以从对您的应用程序重要的功能开始。

真正棘手的部分(假设它是一个数学库)将确保它正常工作:您应该拥有与原始库相同的单元测试集。最好的方法是创建一个通过 JNI 调用您的 lib 的 java 包装类,以便您可以在您的 lib 上运行原始单元测试。纯 Objective-C 库(无平台绑定)应该在 OS X 和 iOS 上运行,因此您可以在 OS X 上运行测试。执行以下操作:

  1. 查看原始 Java 库,并在 Objective-C 中创建功能相似的 API:相同类,相同的方法名称。
  2. 获取原始 java 类,并将方法的所有内容替换为对本机库的 JNI 调用。
  3. 在您的库中实现功能。
  4. 运行 java 单元测试(现在调用您的本机库)以确保您的库正常工作。

为了更轻松地进行 JNI 开发,您可以使用 JNA 或列出的任何其他 JNI 包装器 此处

Since this seem to be a library of functions, it would not depend on any platform specific functions.

Porting this should really be straightforward. You can port function by function, maybe start with functions that are important for your app.

The really tricky part (given it's a math lib) will be assuring that it works correctly: you should have the same set of unit tests as original lib. The best would be to create a java wrapper classes that call your lib via JNI so that you could run original unit tests on your lib. Pure Objective-C lib (no platform bindings) should run on both OS X and iOS, so you can run tests on OS X. Do something like this:

  1. Look at original Java lib, and create functionally similar API in Objective-C: Same classes, same method names.
  2. Take the original java classes and replace all content of methods with JNI calls to your native library.
  3. Implement functionality in your lib.
  4. Run java unit tests (which now calls your native lib) to make sure your lib works correctly.

For easier JNI development you can use JNA or any other JNI wrapper listed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文