Objective-C:保存文本。最好的解决方案?
这可能听起来像一个新手问题(事实上,确实如此),但我无法弄清楚应该使用什么来在会话之间保存:
- NSStrings
- NStextStorages
我找到了一些替代方案,但我不知道哪个最适合案例及其原因:
- 核心数据(或者与之无关?)
- SQL
编辑: 我有一个简单的界面,可以将“帖子”添加到数据库(尚不存在,因此我的问题)。每个“帖子”都有一个“标题”、一两个“作者”和一个“正文”。虽然“标题”和“作者”是纯字符串 (NSStrings
),但“正文”是富文本 (NSTextStorage
)。但我不想保存文件,我想生成一个数据库,然后可以使用该数据库自动格式化并生成 PDF 文件(供我打印)。我一直在阅读 Core Data,它看起来像是可行的方法,我只是不确定如何将我的数据转换为 PDF 格式。
This may sound like a noobish question (in fact, it is), but I can't figure out what I should use to save between sessions:
- NSStrings
- NStextStorages
I've found some alternatives, but I don't know which is best for the case and why:
- Core Data (or has it nothing to do?)
- SQL
Edit: I have a simple interface that adds "posts" to a database (that doesn't exist yet, hence my question). Each "post" has a "title" one or two "authors" and a "body". While the "title" and the "authors" are plain strings (NSStrings
), the "body" is rich text (NSTextStorage
). But I don't want to save files, I want to generate a database that I could then use to format automatically and generate a PDF file (for me to print). I've been reading Core Data and it looks like the way to go, I'm just not sure how I could then convert my data and format it into a PDF.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Core Data 可能非常适合您正在做的事情,尽管您使用 Core Data 执行的任何操作都可以使用 SQL(如果您已经了解它)。
阅读核心数据指南。基本上,您可以布置架构,然后可以从托管对象上下文中添加或删除托管对象。 Core Data 很好,因为它可以免费进行大量验证,并且性能良好。
Core Data would probably be great for what you're doing, although anything you do with Core Data you can probably do with SQL if you already know it.
Read the Core Data guides. Basically you lay out your schema and then can add or remove managed objects from the managed object context. Core Data is nice because it can do a lot of validation for free, and is good performance.
不久前我也遇到过类似的情况..虽然我是为iPhone开发的,但我相信原理是一样的..我发现核心数据非常有用,一旦我掌握了它,它就被证明是非常有用的有用..
如果您保存大量信息/数据,那么核心数据可能是正确的选择..
希望这有帮助:)
I was in a similar situation not too long ago.. and although im developing for iPhone, i belive the principle would be the same.. i found core data to be very useful, once i got to grips with it it proved to be quite useful..
if your saving a lot of information/data, than core data may be the way to go..
hope this helps :)