0

我正在编写一个非常简单的应用程序,它可以从指定文件中读取数据并将获取的数据填充到NSTableView. 该文件是一个纯文本文件,其中每一行代表一个对象(我需要解析文件)。我想使用 Core Data,我的问题是 Cocoa 的方法是什么?

我的第一个想法是解析文件并为代表一行的实体创建实例。我不确定这是最好的解决方案。稍后我会写出对文件的更改(保存后?还是在给定时间后自动?)

我的配置是 Mountain Lion 和最新的 XCode。

4

1 回答 1

0

A single entity with a number of attributes sounds good. If you had an attribute which holds a reasonable amount of data and was repeated on a number of 'rows' then it would be a candidate for another entity.

Yes, each instance of your entity would represent one row in your table.

Personally, I would either save on request by the user, or not have a save button and save each change. Your issue is the conversion between your in-memory store and on-disk store. Using a plain text file doesn't help (though, depending on the file format, it could be possible to edit individual lines in the file using NSFileHandle).

Generally it would still make more sense to use a better format like XML or JSON and then make use of a framework like RestKit which will do all of the parsing and mapping for you (after you specify the mapping configuration).

You can also use bindings to connect your data to your NSTableView. Another ref.

于 2013-08-24T10:29:32.577 回答