iOS 中的多语言文档 (RTF):文件、SQLite、核心数据?如何?

发布于 2024-10-20 20:40:05 字数 702 浏览 3 评论 0原文

我正在制作我的第一个 iOS 应用程序,并且面临着我的第一个(小)问题。

该应用程序将是一个非常经典的 iOS UI 体验:我的意思是,表格视图、选项卡栏、推送控制器等显示文档(来自现有的 RTF 文件)、音频和视频文件。

我的 RTF 有混合语言,全部由 iOS 支持,我认为这很重要,不是吗?

考虑到音频和视频显然会存储在沙箱文档目录中,我对 RTF 不太确定。

我希望它在每个设备上都具有很强的反应性,所以我的想法是将我的 RTF 存储在核心数据实体中(使用二进制类型),并使用 NSAttributedString 将其获取到我的应用程序中,NSAttributedString 可以响应 initWithRtf 消息。

我想之后我必须将其加载到 UIWebView 中?或者简单地将此 NSAttributedString 显示到文本视图中将保留其格式?

但我不知道如何使用 Core Data 预填充数据库来发送我的应用程序。

所以我的问题是:

  • 将这些 RTF 存储在 Core Data 中是个好主意吗?它真的比直接从文档文件夹加载 RTF 文件的简单 UIWebView 更快吗?也许 SQLite 更适合我的情况?
  • 如何将数据库预填充到我的应用程序中?
  • 关于我的 RTF 中的多种语言有什么具体考虑吗? (例如,拉丁语和非拉丁语语言放入同一文件中)。

多谢 !再见。

I'm making my first iOS App, and I'm facing my first (little) issue.

The App will be a very classical iOS UI Experience : I mean, table views, tab bar, push controllers etc. displaying documents (from RTF files already existing), audio and video files.

My RTFs have mixed languages, all supported by iOS, I think it's important isn't it ?

Considering audio and video will obviously stored in the sandbox documents directory, I'm not so sure for the RTF.

I want it to be very reactive, on every devices, so my idea was to store my RTFs in a Core Data entity (using the binary type) and getting it in my application with NSAttributedString which can respond to the initWithRtf message.

I guess that after that I'll have to load it into a UIWebView ? Or simply displaying this NSAttributedString into a textview will preserve it's formatting ?

But I don't know how to ship my application with a Core Data pre-filled database.

So here are my questions :

  • Is it a good idea to store those RTFs in Core Data ? Is it really faster than a simple UIWebView where I would load the RTF file from documents folder directly ? Maybe SQLite is better for my case ?
  • How to pre-fill a database into my application ?
  • Any specific consideration about the multiple languages into my RTFs ? (Latin AND non latin languages into a same file for exemple).

Thanks a lot ! Bye.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2024-10-27 20:40:05

使用 NSAttributedString 在我的应用程序中获取它,它可以响应 initWithRtf 消息。

那是行不通的。 -initWithRTF:documentAttributes: 目前仅在 OS X 上可用。要将 RTF 文件转换为 iOS 上的 NSAttributedString 目前需要手动解析该文件(我们希望iOS 5 中发生变化)。

我想之后我必须将其加载到 UIWebView 中?或者简单地将此 NSAttributedString 显示到文本视图中将保留其格式?

UIWebView 无法显示 NSAttributedString。 UITextView 也不能。您必须使用核心文本函数自己绘制文本。或者从一开始就使用 HTML 并在 Web 视图中显示文本。

将这些 RTF 存储在 Core Data 中是个好主意吗?它真的比直接从文档文件夹加载 RTF 文件的简单 UIWebView 更快吗?也许 SQLite 更适合我的情况?

普通文件有什么问题?这将是我的第一个选择,因为它似乎是最简单的。如果您根本不知道某个东西是否需要优化,那么您不必担心它是否需要优化。但由于您可以使用 Core Data 或普通 SQLite 存储任意二进制数据,因此这绝对是可能的。

如何将数据库预填充到我的应用程序中?

只需将 Core Data 数据存储文件包含在应用程序包中即可。如果需要写入此数据库,您的代码需要在首次启动时将文件从捆绑包复制到应用程序的文档目录。

getting it in my application with NSAttributedString which can respond to the initWithRtf message.

That won't work. -initWithRTF:documentAttributes: is currently only available on OS X. To convert an RTF file into an NSAttributedString on iOS requires manual parsing of the file at the moment (let's hope that changes with iOS 5).

I guess that after that I'll have to load it into a UIWebView ? Or simply displaying this NSAttributedString into a textview will preserve it's formatting ?

UIWebView can't display NSAttributedStrings. Neither can UITextView. You would have to use the Core Text functions to draw the text yourself. Or use HTML from the beginning and display the text in a web view.

Is it a good idea to store those RTFs in Core Data ? Is it really faster than a simple UIWebView where I would load the RTF file from documents folder directly ? Maybe SQLite is better for my case ?

What's wrong with plain files? That would be my first option because it seems to be the simplest. You shouldn't worry about optimizing something if you don't know if it needs optimizing at all. But since you can store arbitrary binary data with Core Data or plain SQLite, it's definitely possible.

How to pre-fill a database into my application ?

Just include the Core Data datastore file in your app's bundle. If this database needs to be written to, your code needs to copy the file from the bundle to your app's Documents directory on first launch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文