简体   繁体   English

将iOS核心数据导入android sqlite

[英]Import iOS coredata into android sqlite

I want to share data between my android and iOS apps. 我想在Android和iOS应用之间共享数据。 I've exported core data sqlite from this directory, ~/Library/Application Support/iPhone Simulator/User/Applications//Documents/.sqlite 我已经从此目录〜/ Library / Application Support / iPhone Simulator / User / Applications // Documents / .sqlite导出了核心数据sqlite

Which is fine I think. 我认为这很好。 The problem arises when I've try to open the sqlite file with sqlite browser. 当我尝试使用sqlite浏览器打开sqlite文件时,就会出现问题。 As it gives an error, "Not a sqlite 3 file". 由于出现错误,“不是sqlite 3文件”。 I was thinking that I will import that coredata sqlite file into android. 我当时在想将coredata sqlite文件导入android。

However my question is, What is the proper way to import iOS coredata into android sqlite? 但是我的问题是, 将iOS核心数据导入android sqlite的正确方法什么?

There's no really good way to take a SQLite file created by Core Data and use it anywhere else. 没有真正好的方法来获取由Core Data创建的SQLite文件并在其他任何地方使用它。 Core Data is more than just a SQLite wrapper, it provides a rather different API with different rules and assumptions (for example, Core Data has true many-to-many relationships, so you don't need to create join tables). Core Data不仅仅是SQLite包装器,它还提供了一个完全不同的API,具有不同的规则和假设(例如,Core Data具有真正的多对多关系,因此您无需创建联接表)。 SQLite is an implementation detail. SQLite是一个实现细节。 As a result, the schema in one of these SQLite files has only a passing resemblance to the Core Data object model. 结果,这些SQLite文件之一中的模式仅与Core Data对象模型具有相似的传递。 You could open the SQLite file anywhere, but making sense of it might be a problem. 您可以在任何地方打开SQLite文件,但是弄清楚它可能是一个问题。

If you want to use the same data and you're already using Core Data, you'll need to have your app export the data to something more portable-- CSV maybe, or a more generic SQLite file, or anything else that looks good to you. 如果您想使用相同的数据并且已经在使用Core Data,则需要让您的应用将数据导出到更便携的文件中-也许是CSV,或者是更通用的SQLite文件,或者其他看起来不错的文件给你。

If you're not already using Core Data and you need this portability, you might be better off using SQLite directly with whatever schema you need. 如果您尚未使用Core Data并且需要这种可移植性,那么最好直接将SQLite与所需的任何架构一起使用。 You don't have to go through Core Data to use SQLite on iOS if it's not what you need. 如果不需要,您无需遍历Core Data即可在iOS上使用SQLite。 You can either use SQLite's API directly or else go via wrappers like PLDatabase or FMDB . 您可以直接使用SQLite的API,也可以通过PLDatabaseFMDB之类的包装器进行访问

Core Data's SQLite store is a vanilla SQLite file, so something else is going wrong with your import. Core Data的SQLite存储是普通的SQLite文件,因此导入时出现了其他问题。 However the mapping that Core Data makes from its entities to the SQLite store is explicitly implementation dependent and, as a result, is not part of the specification and is therefore not documented. 但是,Core Data从其实体到SQLite存储库的映射显式依赖于实现,因此,它不属于规范的一部分,因此未记录在案。 As it is allowed to change between versions of Core Data it's also not necessarily safe to reverse engineer it*. 由于允许在Core Data版本之间进行更改,因此对它进行反向工程也不一定安全*。

As of iOS 5, if you really want to use Core Data and SQLite then what you can do is write your own NSIncrementalStore . 从iOS 5开始,如果您真的想使用Core Data和SQLite,那么您可以编写自己的NSIncrementalStore That'll allow you to impose any mapping from Core Data to SQLite that you desire. 这样,您就可以将所需的从Core Data映射到SQLite。 The downside is that it's barely documented. 缺点是它几乎没有记录。

(*) although it is sometimes helpful to poke around in there; (*)虽然在其中戳戳有时会有所帮助; you can supply the command-line argument -com.apple.CoreData.SQLDebug 1 to have Core Data dump all the SQL commands it performs to the console, then it can be a helpful performance diagnostic to open your persistent store in SQLite and check out the query plans, to make sure you're indexing the correct things. 您可以提供命令行参数-com.apple.CoreData.SQLDebug 1以使Core Data将其执行的所有SQL命令转储到控制台,然后在SQLite中打开持久存储并检出它可能是有用的性能诊断查询计划,以确保您索引正确的内容。

Have not export any iOS SQLite file so I dont know how do you export yours. 还没有导出任何iOS SQLite文件,所以我不知道如何导出您的文件。 Maybe you need analysis your file bytes code? 也许您需要分析文件字节码? Look this http://www.sqlite.org/fileformat.html 看看这个http://www.sqlite.org/fileformat.html

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

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