如何在Core Data中存储矩阵或向量数据结构?
我正在构建一个 iPhone 应用程序,需要在核心数据中存储某种矩阵或向量数据。由于某些未知的原因,iPhone SDK 的基础类中没有包含任何类型的矩阵数据结构,因此我构建了自己的数据结构,它使用 NSMutableArrays
的 NSMutableArray
来存储数据。到目前为止,一切都很好。
我想将此数据结构存储在我的核心数据存储中,并且我已经阅读了有关使用 可转换属性来存储非标准结构。当我尝试存储数据结构时,出现以下错误: [FCMatrixencodeWithCoder:]: unrecognized Selector sent to instance
我正在运行的代码如下,本质上只是在我的实例中设置属性实体:
[collection setMatrix:matrix];
我此时的假设是,由于矩阵是一个可转换的属性,并且我的 FCMatrix 类是一个自定义对象(从 NSObject 的子类),因此我需要在我的数据结构类中实现方法 encodeWithCoder
,以便Core Data 可以正确地编码、存储然后解码数据以重新创建我的数据结构。谁能解释一下执行此操作的最佳方法?
另一个想法 - 我想知道你的想法 - 是重建我的 FCMatrix 类,使其成为 NSMutableArray 的子类。如果 NSMutableArray 可以变形,那么我就准备好了。
或者,我确信这工作量太大,必须有一种更简单的方法来做到这一点。有人有在核心数据中存储矩阵数据的经验吗?
I am building an iPhone application that needs to store some sort of matrix or vector data in core data. For some unknown reason, the iPhone SDK does not include any kind of matrix data structure in its foundation classes, so I built my own data structure which uses an NSMutableArray
of NSMutableArrays
to store the data. So far so good.
I'd like to store this data structure in my core data store, and I've read about using transformable attributes to store non-standard structures. When I try to store the data structure, I get the following error: [FCMatrix encodeWithCoder:]: unrecognized selector sent to instance
The code that I am running is as follows, essentially just setting the attribute in my entity:
[collection setMatrix:matrix];
My assumption at this point is that since matrix is a transformable attribute, and my FCMatrix class is a custom object (subclassed from NSObject), I need to implement the method encodeWithCoder
in my data structure class so that Core Data can properly encode, store, and then decode the data to recreate my data structure. Can anyone explain the best way to do this?
Another idea - I'd like to know what you think - is to rebuilt my FCMatrix class to be subclassed from NSMutableArray. If NSMutableArray could be transformable, then I would be set.
Alternately, I am convinced that this is way too much work and that there has to be an easier way to do this. Does anyone have any experience storing matrix data in core data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许考虑将数组转换为字节,它可以存储在 NSData 对象中并放入二进制属性中。
Maybe look into converting the arrays into bytes, which can be stored in an
NSData
object and placed into a binary attribute.我想出了一个解决我自己问题的方法:
I have come up with a solution to my own problem:
NSMutableArray
objects in core data as transformable attributes.