简体   繁体   English

持久存储Cocoa / MacOSX

[英]Persistent Storage Cocoa/MacOSX

When writing an application for MacOSX, using Cocoa/Objective-C, I'd like to be able to store the data entered by the users. 在使用Cocoa / Objective-C编写MacOSX应用程序时,我希望能够存储用户输入的数据。 There will only be one user per installation at the moment; 目前每个安装只有一个用户; however, I'd like to get an idea of how storage methods change if it were multiple users per installation. 但是,我想知道如果每个安装有多个用户,存储方法会如何变化。

In the case of 1 user per installation, should I stick to SQLLite for persistent storage, or what's the recommendation? 在每个安装1个用户的情况下,我应该坚持使用SQLLite进行持久存储,还是建议什么?

If I were to allow for multiple users per installation, what persistent storage method would be prefered? 如果我每次安装允许多个用户,那么首选哪种持久存储方法?

您可以使用Core Data并为每个用户创建一个持久存储(在〜/ Library / Application Data / My App /中)

You could also consider using an NSDictionary as your internal storage mechanism and then write them out to property list files using [NSDictionary writeToFile:atomically:]. 您还可以考虑使用NSDictionary作为内部存储机制,然后使用[NSDictionary writeToFile:atomically:]将它们写入属性列表文件。 A friend of mine likes to refer to dictionaries as God's data structure (tongue in cheek). 我的一个朋友喜欢将词典称为上帝的数据结构(舌头在脸颊)。

If your data size is modest there are several advantages to this: human readable, human writable, changeable. 如果您的数据量适中,则有几个优点:人类可读,人类可写,可更改。

What kind of data do you want so save? 您想要保存哪种数据? Of course you can still use sqlite to store data for multiple users (eg Firefox does this). 当然你仍然可以使用sqlite为多个用户存储数据(例如Firefox就是这样)。

But depending on your data you might want to save it into normal files/documents? 但根据您的数据,您可能希望将其保存到普通文件/文档中? Take a look at the NSCoding protocol and the abstract NSCoder class. 看一下NSCoding协议和抽象的NSCoder类。 Or check out the document architecture ( NSDocumentController , NSDocument , and NSWindowController ). 或者查看文档体系结构( NSDocumentControllerNSDocumentNSWindowController )。

There will only be one user per installation at the moment; 目前每个安装只有一个用户; however, I'd like to get an idea of how storage methods change if it were multiple users per installation. 但是,我想知道如果每个安装有多个用户,存储方法会如何变化。

Format is irrelevant as long as you only save data within the user's Home directory by default. 只要您在默认情况下仅将数据保存在用户的主目录中,格式就无关紧要了。

Your options include property lists, Core Data (more an architectural decision—you either base your app on Core Data or don't use it), SQLite, NSKeyedArchiver, and your own custom format. 您的选项包括属性列表,核心数据(更多是架构决策 - 您的应用程序基于Core Data或不使用它),SQLite,NSKeyedArchiver和您自己的自定义格式。

i would start storing data onto the cloud rather than store locally. 我会开始将数据存储到云上而不是本地存储。 Now that ipad is coming out, what if your app is used on the iphone and ipad as well. 现在ipad即将问世,如果你的应用程序也在iphone和ipad上使用了。 If you store the data on the cloud, both the iphone app and the ipad can use the same data. 如果您将数据存储在云端,则iphone应用程序和ipad都可以使用相同的数据。 If you store locally, obviously, iphone app and ipad app cannot use the same data. 如果你在本地存储,显然,iphone app和ipad app不能使用相同的数据。

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

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