Core Data - Iterating through the attributes of a NSManagedObject

后端 未结 2 1769
傲寒
傲寒 2021-02-07 11:20

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

I have a core data object, for example student.

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

2条回答
  •  Happy的楠姐
    2021-02-07 12:10

    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);
    }
    

    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/

提交回复
热议问题