从 Android 访问 iOS 核心数据
我使用 Core Data 按照书本开发了一个简单的 iPhone 应用程序。数据是不可变的,存储在预加载的 sqlite 数据库中,由 Core Data 管理。
现在我需要为 Android 开发(几乎)相同的应用程序。我即将编写一组非常基本的类来模仿 Core Data,并从完全相同的 sqlite 数据库中读取数据。
在开始之前,我想知道是否有人知道有一个 Android 库可以做到这一点。
理论上,您几乎可以提供与 iOS 相同的 API,甚至还可以解析对象模型。
I developed a simple iPhone app by the book, using Core Data. The data is immutable and stored in a preloaded sqlite database, managed by Core Data.
Now I need to develop the (almost) same app for Android. I'm about to write a very basic set of classes that mimic Core Data, and read from the exact same sqlite database.
Before getting started on this, I was wondering if anyone knows about an Android library that does just this.
In theory, you could almost literally provide the same API as iOS does, maybe even parsing the object model as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
核心数据有自己的数据结构,你可以查看它,你会看到类似这样的内容:
来自的表格您的模型以 Z 为前缀,因此您可以在 Android 中使用 SQL 查询完美地查询此 SQLite 数据库。
注意:使用模拟器运行应用程序后,您可以在以下文件夹中找到此 SQLite 文件:
/Users//Library/Application Support/iPhone Simulator//Applications//Documents /.sqlite
Core Data have its own data structure you can look at it and you will see something like this:
Tables from your model are prefixed by Z, so you can perfectly query this SQLite Database with SQL queries in Android.
Note: you can find this SQLite file after runnig your app with Simulator in the folder:
/Users/<you_name>/Library/Application Support/iPhone Simulator/<ios_version>/Applications/<app_id>/Documents/<app_name>.sqlite
在一个更复杂的项目中,我们在将代码从 iOS 迁移到 Android 时使用 greenDAO 作为 Core Data 的替代品。它没有附带视觉建模,但基本操作非常相似。作为一个 ORM 工具,greenDAO 将 Java 对象映射到 SQLite,并提供诸如关系之类的东西。
In a more complex project, we used greenDAO as an replacement for Core Data when migrating code from iOS to Android. It does not come with visual modelling, but the basic operations quite similar. Being an ORM tool, greenDAO maps Java objects to SQLite and offers stuff like relations, too.