Created
August 3, 2019 13:38
-
-
Save NathanLawrence/f9da5f2638ae2f76822a7f88c68d609c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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