Вы не можете использовать enum class
для достижения своей цели. Однако вы можете использовать namespace
с набором жестко закодированных constexpr
объектов:
struct Country
{
int _id;
};
namespace Countries
{
namespace Europe
{
constexpr Country Italy{0};
constexpr Country France{1};
};
};
Использование:
myC.foo(Countries::Europe::Italy);
Предполагая, что существует обратная связь «один ко многим» между сущностями «Актер» и «Фильм», вы можете просто получить сущность для Чака Норриса так же, как и любую конкретную сущность, и затем получить доступ к массиву сущностей Movie, прикрепленных к отношениям в сущности Actor.
// Obviously you should do proper error checking here... but for this example
// we'll assume that everything actually exists in the database and returns
// exactly what we expect.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Actor" inManagedObjectContext:self.managedObjectContext];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name LIKE[c] 'Chuck Norris'"];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setPredicate:predicate];
// You need to have imported the interface for your actor entity somewhere
// before here...
NSError *error = nil;
YourActorObject *chuck = (YourActorObject*) [[self.managedObjectContext executeFetchRequest:request error:&error] objectAtIndex:0];
// Now just get the set as defined on your actor entity...
NSSet *moviesWithChuck = chuck.movies;
В качестве примечания, этот пример, очевидно, предполагает использование свойств 10.5, но вы можете сделать то же самое в 10.4, используя методы доступа.