0
votes

I always have my core data entities to use NSManagedObject subclasses.

Inside these classes I always have methods like this

+ (Entity *)newItemWithName:(NSString *)name InManagedObjectContext:(NSManagedObjectContext *)context {

// bla bla bla

and inside these methods you will eventually find something like

anItem = [NSEntityDescription insertNewObjectForEntityForName:@"Entity" inManagedObjectContext:context];
anItem.name = name;

My problem is this @"Entity".

Is there a way to refer to the entity's name from within these methods without having to type the entity name every time and minimize the chance of a typo/bug? or in other words, there is something else that could be put there to discover the name of the entity by itself?

thanks.

1

1 Answers

2
votes

You could use NSStringFromClass([self class]).

However, this is also fragile as you might change the implementing class name in IB.