2

I have a User : NSManagedObject. What's the best way to get an NSAttributeDescription of it's userID attribute?

ma11hew28
  • 121,420
  • 116
  • 450
  • 651

1 Answers1

6

Assuming you have access to a User *user instance, you could do:

NSAttributeDescription *userIDAttribute =
    [[user.entity attributesByName] objectForKey:@"userID"];

If you didn't have access to a User *user object but just to the NSManagedObjectContext *context, you could get the NSEntityDescription for User with:

NSEntityDescription *userEntity = [NSEntityDescription entityForName:@"User"
                                              inManagedObjectContext:context];
ma11hew28
  • 121,420
  • 116
  • 450
  • 651