保存、读取、交换自己的文件格式?

发布于 2024-12-04 08:32:01 字数 799 浏览 0 评论 0原文

对于将四个字符串保存为应用程序可以读取并可以共享的自己的文件格式有什么建议吗?

在我的应用程序中,您将能够在某些框中输入一些文本,并且应用程序会显示带有背景图像和这些字符串的视图。现在,我已经能够将其保存为图片,但实际上我想将其保存为自己的文件格式,以便您可以保存不同的文件,这些文件也可以在以后修改,甚至可以通过电子邮件交换并从另一部 iPhone 打开该应用程序。

现在,我编写了用于访问应用程序的文档文件夹以及保存和删除的代码。问题是,我不知道如何将这些字符串存储在文件中(也许是 xml?),然后从我的应用程序中轻松读取它们。

对于交换部分,我发现该链接确实是一个不错的功能:http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

解析 xml似乎没那么困难(以前从未做过): http://ipad.about.com/od/iPad-App-Dev/a/How-To-Parse-Xml-Files-In-Xcode-Objective-C.htm

any recommendations for saving four strings into an own file format that is read by the application and can be shared?

In my app, you will be able to enter some text in some boxes and the app shows a view with an background image and those strings. Now, I am already able to save this as a picture, but I actually want to save it to an own file format so that you can save different files that can be modified afterwards as well or even exchanged via email and opened from another iphone with the app.

Now, I wrote the code for accessing the documents folder of the app, as well as saving and deleting. Thing is, i dont know how to store those strings in a file (perhaps in a xml?) and read them easily afterwards from my application.

For the exchanging part, I found that link which would be a nice feature indeed: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

Parsing xml seems not that difficult (never done it before): http://ipad.about.com/od/iPad-App-Dev/a/How-To-Parse-Xml-Files-In-Xcode-Objective-C.htm

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

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

发布评论

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

评论(3

北方的韩爷 2024-12-11 08:32:01

如果只是一小部分信息,那么将数据存储在文件中的最简单方法是使用 plist - 这里有一个很好的教程 - http://www.icodeblog.com/2009/02/14/loading-data-from-plist-files/

If it's only a small bit of infomation then the easiest way to store your data in a file would be using a plist - there's a good tutorial here - http://www.icodeblog.com/2009/02/14/loading-data-from-plist-files/

尘世孤行 2024-12-11 08:32:01

除了 plist 之外,您还可以执行以下方法:
1)最简单 - 在文档目录中打开一个文件,写入 4 个字符串(使用任何有用的分隔符/字符串结尾标记 - 回车符?)并每次都覆盖它们。 (即这是您的文件,您可以按照您喜欢的方式格式化它)
2) 稍微困难一些 - 使用 Apple 的 NSArchive 来打包和解包字符串。
3) 可能的过度杀伤——将它们直接存储在 SQLite 数据库中
4)主要的杀伤力——将它们存储在CoreData中。

当然,“过度杀伤”选项还为您提供了额外的功能,如果您的应用程序功能超出了您所概述的范围,这些功能可能会很有用。

通过共享,我认为简单的复制和粘贴可能就足够了,但也可以通过电子邮件发送它,或者触发另一个应用程序的 URL 方案以使其打开它,并将字符串作为 URL 的一部分发送。您必须知道其他应用程序能够将您的字符串解释为 URL 的一部分,因此您可能必须自己编写它。

In addition to the plist, you could also do the following approaches:
1) simplest - open a file in your documents directory, write the 4 strings (using whatever delimiter/end of string marker is useful - carriage return?) and overwrite them each time through. (i.e. it's your file, you can format it how you like)
2) mildly harder - use Apple's NSArchive to pack and unpack the strings.
3) possible overkill - store them directly in a SQLite database
4) major overkill - store them in CoreData.

Of course, the "overkill" options also provide you with extra features which may be of use if your app functionality extends beyond what you've outlined.

By sharing, I would think that simple copy and paste might be enough, but there's also sending it via email, or tripping another app's URL scheme to make it open it and sending the strings as part of the URL. You'd have to know that the other app would be able to interpret your strings as part of the URL, so you might have to write it yourself.

简单爱 2024-12-11 08:32:01

好吧,我在 NSString 文档中发现了一个非常好的方法:

–writeToFile:atomically:encoding:error:

我想我要用 /n 分隔字符串并将它们保存到 .txt。当我之后要读取文件时,我得到字符串,将其划分为子字符串。我想这样就可以了。

最后一个问题:是否可以替换文件的内容,这样我就不需要每次想要更改某些内容时都创建一个新文件?

谢谢!

Okay guys I found that very nice method in the NSString documentation:

–writeToFile:atomically:encoding:error:

I think I am gonna separate my strings by /n and save them to a .txt. When I am gonna read the file afterwards, i am getting the string, divide it to substrings. That will do it, I guess.

One last question: Is it possible to replace the content of my file so that I won't need to create a new file every time i want to change something?

Thanks!

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