我是核心数据的noob,所以这里.
我有一个核心数据对象,例如学生.
有没有任何简单的方法来迭代对象学生?或者我必须将数据转换成某种类型的字典?
如果我需要将其转换为字典,是否有任何支持?或者我必须自己写这个函数.
非常感谢您的帮助,
斯蒂芬
解决方法
这是一个非常简单的方法来迭代一个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的博客:http://oleb.net/blog/2011/05/inspecting-core-data-attributes/的线索(加上更多)