Question

SQL Command

SELECT GAMELOCALTEAM FROM GAME WHERE GAMELOCALTEAM NOT IN ‘TBC’ ORDER BY GAMELOCALTEAM

I would like to write sql command in objective c. My worte code below

NSManagedObjectContext * context = ((AFLAppDelegate *)[[UIApplication sharedApplication] delegate] ).managedObjectContext;
NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@“game”];
NSEntityDescription *entity = [NSEntityDescription entityForName:@“game” inManagedObjectContext:context];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT(gamelocalteam IN 'tbc')"];
[fetch setPredicate:predicate];
NSSortDescriptor *sortDescreptor =[[NSSortDescriptor alloc]initWithKey:@"gamelocalteam" ascending:YES];
[fetch setSortDescriptors:[NSArray arrayWithObject:sortDescreptor]];
NSAttributeDescription* attributeDescription = [entity.attributesByName objectForKey:@"gamelocalteam"];
[fetch setPropertiesToFetch:[NSArray arrayWithObjects:attributeDescription, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:attributeDescription]];
[fetch setResultType:NSDictionaryResultType];
NSError *error = nil;
_team = [context executeFetchRequest:fetch error:&error];

Predicate Format is @"NOT(gamelocalteam IN 'tbc') if this call app is crashing.

Is possible do NOT IN?

Was it helpful?

Solution

Try it

@"NOT gamelocalteam contains[cd] 'tbc'"

Code Below

NSManagedObjectContext * context = ((AFLAppDelegate *)[[UIApplication sharedApplication] delegate] ).managedObjectContext;
NSFetchRequest* fetch = [NSFetchRequest fetchRequestWithEntityName:@“game”];
NSEntityDescription *entity = [NSEntityDescription entityForName:@“game” inManagedObjectContext:context];
NSPredicate *predicate = [NSPredicate predicateWithFormat:>@"NOT gamelocalteam contains[cd] 'tbc'"];
[fetch setPredicate:predicate];
NSSortDescriptor *sortDescreptor =[[NSSortDescriptor alloc]initWithKey:@"gamelocalteam" ascending:YES];
[fetch setSortDescriptors:[NSArray arrayWithObject:sortDescreptor]];
NSAttributeDescription* attributeDescription = [entity.attributesByName objectForKey:@"gamelocalteam"];
[fetch setPropertiesToFetch:[NSArray arrayWithObjects:attributeDescription, nil]];
[fetch setPropertiesToGroupBy:[NSArray arrayWithObject:attributeDescription]];
[fetch setResultType:NSDictionaryResultType];
NSError *error = nil;
_team = [context executeFetchRequest:fetch error:&error];

OTHER TIPS

Your predicate code will look like below,

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"NOT (%K CONTAINS[c] %@)",@"someKey", [NSString stringWithFormat:@"Some String"]];

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top