How to get NSAttributeDescription?

1.1k Views Asked by At

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

1

There are 1 best solutions below

0
On

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];