将持久数据保存为CoreData的txt文件是安全的吗? [英] Is it safe to save persistent data as txt file for CoreData?

查看:119
本文介绍了将持久数据保存为CoreData的txt文件是安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用程序使用CoreData,并且一些表需要在第一次打开应用程序时填充默认值,因为CoreData依赖于设备。

My iOS app uses CoreData and some tables need to be filled with default values every first time the app is opened since CoreData device-dependent.

NSUserDefaults 以检查它是否是第一次打开。如果是第一次,我通过逐行读取并以某种方式分隔,从而填充表格(在CoreData中),其中已经创建的值以及从txt文件格式化的行。

So I am using NSUserDefaults to check whether it is first time open. If it is first time, I fill tables (on CoreData) with the values which I have already created and formatted lines from the txt file by reading line by line and separating in a way.

我的问题是,这种操作使用txt文件是安全和最快的方法吗?

And my question is, is it safe and fastest way to use txt file for such operation?

推荐答案

选项将是在您的应用程序包中保留一个罐装的sqlite文件,并检查文档目录中是否存在SQLite文件。如果文件不存在,请将应用程序包中的预设数据复制到您的文档目录。

A better option would be to keep a "canned" sqlite file in your app bundle and check for the existence of the SQLite file in your documents directory. If the file does not exist, copy the canned data from the app bundle to your documents directory.

这将跳过整个解析逻辑,并允许您的应用程序更快启动。

That will skip the entire parsing logic and will allow your application to launch faster.

这篇关于将持久数据保存为CoreData的txt文件是安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆