即将(Java)库移植到 Objective-C:方法论?
我是一名 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
随心所欲地开始。一般来说,您需要从核心附近开始,然后逐步解决。只需记住这三个步骤:
所以不要担心让它看起来漂亮或立即发生任何事情,只需让它按照需要的方式工作,测试它即可。然后看看如果可能的话可以在哪里重构等等。
Just start wherever you please. Generally, you'll want to start near the core, and work your way out. Just remember these three steps:
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.
由于这似乎是一个函数库,因此它不依赖于任何特定于平台的函数。
移植这个应该非常简单。您可以按功能移植功能,也许可以从对您的应用程序重要的功能开始。
真正棘手的部分(假设它是一个数学库)将确保它正常工作:您应该拥有与原始库相同的单元测试集。最好的方法是创建一个通过 JNI 调用您的 lib 的 java 包装类,以便您可以在您的 lib 上运行原始单元测试。纯 Objective-C 库(无平台绑定)应该在 OS X 和 iOS 上运行,因此您可以在 OS X 上运行测试。执行以下操作:
为了更轻松地进行 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:
For easier JNI development you can use JNA or any other JNI wrapper listed here.