Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active August 29, 2015 14:19
Show Gist options
  • Save Koze/8b974a35da71d63f81b0 to your computer and use it in GitHub Desktop.
Save Koze/8b974a35da71d63f81b0 to your computer and use it in GitHub Desktop.
NSPredicate with UTI
- (void)testImageUTI
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF UTI-CONFORMS-TO %@", (__bridge NSString *)kUTTypeImage];
NSLog(@"%@", predicate);
// SELF UTI-CONFORMS-TO "public.image"
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeJPEG]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypePNG]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeGIF]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeMPEG4]);
// 0
}
- (void)testAudioUTI
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF UTI-CONFORMS-TO %@", (__bridge NSString *)kUTTypeAudio];
NSLog(@"%@", predicate);
// SELF UTI-CONFORMS-TO "public.audio"
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeMP3]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeMPEG4Audio]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeWaveformAudio]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeMPEG4]);
// 0
}
- (void)testEqualsUTI
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF UTI-EQUALS %@", (__bridge NSString *)kUTTypeJPEG];
NSLog(@"%@", predicate);
// SELF UTI-EQUALS "public.jpeg"
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypeJPEG]);
// 1
NSLog(@"%d", [predicate evaluateWithObject:(__bridge NSString *)kUTTypePNG]);
// 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment