Borut Tomazin
Borut Tomazin

Reputation: 8138

Get CoreData object data type based on input string

Is it possible to detect object type from CoreData model based on input string?

My CoreData model "myEntity" has many objects of type NSStrings and NSNumbers, e.g. properties like "name", "lastName", etc.

In a query I want to determine object type (string or number) for let say "lastName" based on input string like that:

if ([myEntity.{lastName} isMemberOfClass:[NSString class]]) {}

Where {lastName} is dynamic text.

Is this even possible?

Upvotes: 0

Views: 182

Answers (1)

Do you meen something like this:

NSString* inputString = @"lastName";
if ([[myEntity valueForKey:inputString] isMemberOfClass:[NSString class]]) {} 

If so just be carefull to validate the string.

Upvotes: 3

Related Questions