简体   繁体   English

将sqlite数据导入CoreData

[英]Bringing sqlite data into CoreData

In our app, we download about 48 sqlite files each around 300kb in size and save it to the disk. 在我们的应用中,我们下载了约48个sqlite文件,每个文件的大小约为300kb,并将其保存到磁盘中。 When user goes into a module, a subset of the data from the any of the file is read and displayed based on some conditions. 当用户进入模块时,将根据某些条件读取并显示来自任何文件的数据子集。 As the user scrolls around in the module, when the scrollview stops scrolling, we determine the position where it stopped and accordingly query the appropriate sqlite file to get the data and display on screen. 当用户在模块中滚动时,当scrollview停止滚动时,我们将确定其停止的位置,并相应地查询适当的sqlite文件以获取数据并显示在屏幕上。 This takes about 2 sec to show the data to the user. 这大约需要2秒钟才能将数据显示给用户。 We want to optimize this and I have read that querying CoreData instead of sqlite files can make this faster. 我们想对此进行优化,并且我已经阅读到查询CoreData而不是sqlite文件可以使此过程更快。

So, the question is, should we try to put data from each sqlite file into CoreData and then always query CoreData. 因此,问题是,我们是否应该尝试将每个sqlite文件中的数据放入CoreData中,然后始终查询CoreData。 My concern is that it would be too much data that would need to be inserted this way since we have 48 files. 我担心的是,由于我们有48个文件,因此需要以这种方式插入太多数据。 The other approach is only the subset of data that is fetched should be loaded to CoreData and not all the files. 另一种方法是仅将获取的数据子集加载到CoreData中,而不是所有文件中。 But this would mean that before displaying the data we determine whether it was already fetched and available in CoreData, else we query sqlite. 但这意味着在显示数据之前,我们先确定数据是否已经获取并在CoreData中可用,否则我们将查询sqlite。 Any suggestions as to what would be a better way to go? 关于什么是更好的方法有什么建议吗?

With the amount of info you've provided, it's not possible to really see whether Core Data would make sense for your application. 有了您提供的大量信息,就不可能真正看到Core Data是否对您的应用程序有意义。 You would have to provide a good amount of info for anyone else to have really well-informed opionion on the matter -- and a decision such as this is important. 您必须为其他任何人提供大量信息,以使他们真正了解此事,并且做出这样的决定很重要。

Btw, you seem to be under the impression that all the data would have to go in gigantic database file in Core Data - this isn't the case. 顺便说一句,您似乎给人的印象是所有数据都必须放在Core Data中的巨大数据库文件中-事实并非如此。 You can have many managed object model files (these are end-product persisted database files for Core Data, named .xcdatamodeld ) and open them selectively. 您可以具有许多托管对象模型文件(这些是Core Data的最终产品持久化数据库文件,名为.xcdatamodeld ),然后有选择地打开它们。

Your best bet is to do some research, try and find the crucial differences between Core Data and use of SQLite directly. 最好的选择是进行一些研究,尝试找出Core Data与直接使用SQLite之间的关键区别。 They both have their place. 他们俩都有自己的位置。 Core Data is great in the right circumstance -- it's not a relational database, it's an object graph and persistence manager, and that has important implications. 核心数据在适当的情况下非常有用-它不是关系数据库,它是对象图和持久性管理器,并且具有重要意义。 Core Data has been optimised to the moon and back, so if you use it in the correct circumstances, it's great -- good performance and does some heavy lifting to stop you having to. Core Data已针对月球和月球进行了优化,因此,如果您在正确的环境下使用它,那就太好了-出色的性能,并且会费一些力气阻止您这样做。 But in other circumstances, direct use of SQLite would be a better option. 但是在其他情况下,直接使用SQLite将是更好的选择。 See, for example, this blog post about someone who switched away from Core Data to SQLite. 例如,请参阅此博客文章,介绍某人从Core Data转到SQLite的情况。

Also check out this nice article on the differences. 还可以查看这篇关于差异的不错的文章 And of course read Apple's own guides, and the wikipedia page . 当然,请阅读Apple自己的指南和Wikipedia页面

It's hard for us to answer the question you've asked, but if you have queries about certain more specific aspects of Core Data, post some new questions -- that sort of question is easier to answer. 我们很难回答您所提出的问题,但是如果您对核心数据的某些更具体方面有疑问,请发布一些新问题-这种问题更容易回答。

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

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