Skip to content

Instantly share code, notes, and snippets.

@NathanLawrence
Created August 3, 2019 13:38
Show Gist options
  • Save NathanLawrence/f9da5f2638ae2f76822a7f88c68d609c to your computer and use it in GitHub Desktop.
Save NathanLawrence/f9da5f2638ae2f76822a7f88c68d609c to your computer and use it in GitHub Desktop.
//
// NSPredicate.swift
// Nighthawk
//
// Created by Nathan Lawrence on 8/3/19.
// Copyright © 2019 Nathan Lawrence. All rights reserved.
//
import Foundation
extension NSPredicate {
convenience init(regex: String) {
self.init(format: "SELF MATCHES %@", regex)
}
func or(_ secondaryPredicate: NSPredicate) -> NSCompoundPredicate{
return NSCompoundPredicate(
type: .or,
subpredicates: [
self,
secondaryPredicate])
}
func and(_ secondaryPredicate: NSPredicate) -> NSCompoundPredicate{
return NSCompoundPredicate(
type: .or,
subpredicates: [
self,
secondaryPredicate])
}
func not() -> NSCompoundPredicate{
return NSCompoundPredicate(
type: .not,
subpredicates: [self])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment