Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Created January 26, 2020 14:56
Show Gist options
  • Save tylerhall/2aaab61e32891e3382777204b5d319c5 to your computer and use it in GitHub Desktop.
Save tylerhall/2aaab61e32891e3382777204b5d319c5 to your computer and use it in GitHub Desktop.
var leftExpressions = [
NSExpression(forKeyPath: "pageTitle"),
NSExpression(forKeyPath: "pageDescription"),
NSExpression(forKeyPath: "content"),
NSExpression(forKeyPath: "url")
]
var operatorTypes = [
NSNumber(value: NSComparisonPredicate.Operator.equalTo.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.contains.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.beginsWith.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.endsWith.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.like.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.matches.rawValue),
NSNumber(value: NSComparisonPredicate.Operator.notEqualTo.rawValue)
]
let someTemplate = NSPredicateEditorRowTemplate(leftExpressions: leftExpressions,
rightExpressionAttributeType: NSAttributeType.stringAttributeType,
modifier: NSComparisonPredicate.Modifier.direct,
operators: operatorTypes,
options: Int(NSComparisonPredicate.Options.caseInsensitive.rawValue))
predicateEditor.formattingStringsFilename = "PredicateStrings"
predicateEditor.rowTemplates = [someTemplate]
//
// NSPredicateEditor+FooPredicate.h
// Elephant
//
// Created by Tyler Hall on 1/25/20.
// Copyright © 2020 Click On Tyler. All rights reserved.
//
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSPredicateEditor (FooPredicate)
- (void)exportStrings;
@end
NS_ASSUME_NONNULL_END
//
// NSPredicateEditor+FooPredicate.m
// Elephant
//
// Created by Tyler Hall on 1/25/20.
// Copyright © 2020 Click On Tyler. All rights reserved.
//
#import "NSPredicateEditor+FooPredicate.h"
#import <AppKit/AppKit.h>
@implementation NSPredicateEditor (FooPredicate)
- (void)exportStrings
{
NSData *data = [self performSelector:@selector(_generateFormattingDictionaryStringsFile)];
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF16StringEncoding];
NSLog(@"%@", str);
}
@end
/*
Predicates.strings
Elephant
Created by Tyler Hall on 1/25/20.
Copyright © 2020 Click On Tyler. All rights reserved.
*/
"%[Any]@ of the following are true" = "%1$[Any]@ of the following are true";
"%[None]@ of the following are true" = "%1$[None]@ of the following are true";
"%[pageTitle]@ %[is]@ %@" = "%1$[Title]@ %2$[is]@ %3$@";
"%[pageTitle]@ %[contains]@ %@" = "%1$[Title]@ %2$[contains]@ %3$@";
"%[pageTitle]@ %[begins with]@ %@" = "%1$[Title]@ %2$[begins with]@ %3$@";
"%[pageTitle]@ %[ends with]@ %@" = "%1$[Title]@ %2$[ends with]@ %3$@";
"%[pageTitle]@ %[is like]@ %@" = "%1$[Title]@ %2$[is like]@ %3$@";
"%[pageTitle]@ %[matches]@ %@" = "%1$[Title]@ %2$[matches]@ %3$@";
"%[pageTitle]@ %[is not]@ %@" = "%1$[Title]@ %2$[is not]@ %3$@";
"%[pageDescription]@ %[is]@ %@" = "%1$[Meta Description]@ %2$[is]@ %3$@";
"%[pageDescription]@ %[contains]@ %@" = "%1$[Meta Description]@ %2$[contains]@ %3$@";
"%[pageDescription]@ %[begins with]@ %@" = "%1$[Meta Description]@ %2$[begins with]@ %3$@";
"%[pageDescription]@ %[ends with]@ %@" = "%1$[Meta Description]@ %2$[ends with]@ %3$@";
"%[pageDescription]@ %[is like]@ %@" = "%1$[Meta Description]@ %2$[is like]@ %3$@";
"%[pageDescription]@ %[matches]@ %@" = "%1$[Meta Description]@ %2$[matches]@ %3$@";
"%[pageDescription]@ %[is not]@ %@" = "%1$[Meta Description]@ %2$[is not]@ %3$@";
"%[content]@ %[is]@ %@" = "%1$[Web Page Contents]@ %2$[is]@ %3$@";
"%[content]@ %[contains]@ %@" = "%1$[Web Page Contents]@ %2$[contains]@ %3$@";
"%[content]@ %[begins with]@ %@" = "%1$[Web Page Contents]@ %2$[begins with]@ %3$@";
"%[content]@ %[ends with]@ %@" = "%1$[Web Page Contents]@ %2$[ends with]@ %3$@";
"%[content]@ %[is like]@ %@" = "%1$[Web Page Contents]@ %2$[is like]@ %3$@";
"%[content]@ %[matches]@ %@" = "%1$[Web Page Contents]@ %2$[matches]@ %3$@";
"%[content]@ %[is not]@ %@" = "%1$[Web Page Contents]@ %2$[is not]@ %3$@";
"%[url]@ %[is]@ %@" = "%1$[URL]@ %2$[is]@ %3$@";
"%[url]@ %[contains]@ %@" = "%1$[URL]@ %2$[contains]@ %3$@";
"%[url]@ %[begins with]@ %@" = "%1$[URL]@ %2$[begins with]@ %3$@";
"%[url]@ %[ends with]@ %@" = "%1$[URL]@ %2$[ends with]@ %3$@";
"%[url]@ %[is like]@ %@" = "%1$[URL]@ %2$[is like]@ %3$@";
"%[url]@ %[matches]@ %@" = "%1$[URL]@ %2$[matches]@ %3$@";
"%[url]@ %[is not]@ %@" = "%1$[URL]@ %2$[is not]@ %3$@";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment