0

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?

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Nag Raja
  • 214
  • 2
  • 11
  • This link will help you http://stackoverflow.com/questions/11476466/use-an-nspredicate-to-detect-not-contains – Natarajan Mar 22 '14 at 05:37

2 Answers2

1

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];
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
Taj rajan
  • 601
  • 1
  • 6
  • 20
1

Your predicate code will look like below,

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

Thanks!

Natarajan
  • 3,241
  • 3
  • 17
  • 34