more elegant way to compare string attribute for Entities
Dear all. Currently i need to extract necessary objects from core data but i have just attribute name in entity. TO setup reverse relationship, i find just one way to loop around all objects in managed objects, compare strings for checking necessary attributes accordance and setup relationship. May someone have better way. relationship carrier is part of NamesTranslationRules Entity and connect to Carriers Entity
NSManagedObjectContext *moc = [self managedObjectContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Carriers"
inManagedObjectContext:moc]];
NSArray *carriers = [moc executeFetchRequest:request
开发者_JAVA技巧 error:&error] ;
for (NSManagedObject *carrier in carriers)
{
if ([[carrier valueForKey:@"name"] isEqualToString:[tempRules valueForKey:@"carrier"]]) [namesTranslationRules setValue:carrier forKey:@"carrier"];
}
A parent object's is create at application startup as carrier's name with some attributes. Later user have to choice a name from another source and based on user's choice we have to add appropriate entity, which have already present parent entity carrier.
What do you mean by a reverse relationship? If the relationship is already bi-directional then the reverse will be set up for you automatically by Core Data.
If you mean something else, you can look at using a predicate on your NSFetchRequest
to pre-filter the objects and skip the string comparison.
Update 1
You should know the parent object at the time of the creation and should be connecting them at that time.
Where is the data coming from?
精彩评论