核心数据 - 迭代NSManagedObject的属性 [英] Core Data - Iterating through the attributes of a NSManagedObject

查看:128
本文介绍了核心数据 - 迭代NSManagedObject的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是核心数据的菜鸟,所以这里有。

I am a noob at core data, so here goes.

我有一个核心数据对象,例如学生。

I have a core data object, for example student.

学生有鬃毛属性,如姓名,年龄,dob,地址等。

The student has mane attributes, like name, age, dob, address, and so on.

现在我需要将所有这些属性显示为表视图。

Now I need to display all these attributes into a table view.

有没有简单的方法来迭代对象学生?或者我是否必须将数据转换为某种类型的字典?

Is there any easy way to iterate through the object student? Or do I have to convert the data into some type of dictionary?

如果我需要将其转换为字典,是否有任何支持?或者我必须自己写这个函数。

If I need to convert it to a dictionary is there any support for it? Or do I have to write the function my self.

非常感谢你的帮助,
Stephen

Many thanks for your help, Stephen

推荐答案

这是迭代NSManagedObject的一种非常简单的方法:

Here's a very simple way to iterate over an NSManagedObject:

NSEntityDescription *entity = [myManagedObject entity];
NSDictionary *attributes = [entity attributesByName];
for (NSString *attribute in attributes) {
    id value = [myManagedObject valueForKey: attribute];
    NSLog(@"attribute %@ = %@", attribute, value);
}

如何做到这一点(加上更多)的线索来自Ole Bergmann's博客: http://oleb.net/blog/2011/05/检查-core-data-attributes /

The clues for how to do this (plus lots more) comes from Ole Bergmann's blog: http://oleb.net/blog/2011/05/inspecting-core-data-attributes/

这篇关于核心数据 - 迭代NSManagedObject的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆