|
| 1 | +// |
| 2 | +// QKAttribute.h |
| 3 | +// QueryKit |
| 4 | +// |
| 5 | +// Created by Kyle Fuller on 30/04/2013. |
| 6 | +// |
| 7 | +// |
| 8 | + |
| 9 | +#import <Foundation/Foundation.h> |
| 10 | + |
| 11 | +/** A helper class to generate predicates and sort descriptors for attributes |
| 12 | + on a managed object. |
| 13 | + */ |
| 14 | +@interface QKAttribute : NSObject <NSSecureCoding, NSCopying> |
| 15 | + |
| 16 | +@property (nonatomic, strong, readonly) NSString *name; |
| 17 | + |
| 18 | +/// Initialized the attribute from multiple other attributes |
| 19 | +- (instancetype)initWithAttributes:(QKAttribute *)attribute, ... NS_REQUIRES_NIL_TERMINATION NS_DESIGNATED_INITIALIZER; |
| 20 | + |
| 21 | +/// Initialized the attribute with the given name |
| 22 | +- (instancetype)initWithName:(NSString *)name __attribute((nonnull)) NS_DESIGNATED_INITIALIZER; |
| 23 | + |
| 24 | +/** Returns a Boolean value that indicates whether a given attribute is equal to the receiver |
| 25 | + @param attribute The attribute to compare against the receiver |
| 26 | + @return YES if attribute is equivalent to the receiver |
| 27 | + */ |
| 28 | +- (BOOL)isEqualToAttribute:(QKAttribute *)attribute; |
| 29 | + |
| 30 | +/** Returns an expression for the attributes key-value path */ |
| 31 | +- (NSExpression *)expression; |
| 32 | + |
| 33 | +@end |
| 34 | + |
| 35 | +@interface QKAttribute (Predicate) |
| 36 | + |
| 37 | +/** Returns a predicate for an equality comparison against the supplied value |
| 38 | + @param value To compare against the attribute |
| 39 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 40 | + @return The predicate for this comparison |
| 41 | + @see equal: |
| 42 | + */ |
| 43 | +- (NSPredicate *)equal:(id)value options:(NSComparisonPredicateOptions)options; |
| 44 | + |
| 45 | +/** Returns a predicate for an equality comparison against the supplied value |
| 46 | + @param value To compare against the attribute |
| 47 | + @return The predicate for this comparison |
| 48 | + @see equal:options: |
| 49 | + */ |
| 50 | +- (NSPredicate *)equal:(id)value; |
| 51 | + |
| 52 | +/** Returns a predicate for an unequal comparison against the supplied value |
| 53 | + @param value To compare against the attribute |
| 54 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 55 | + @return The predicate for this comparison |
| 56 | + @see notEqual: |
| 57 | + */ |
| 58 | +- (NSPredicate *)notEqual:(id)value options:(NSComparisonPredicateOptions)options; |
| 59 | + |
| 60 | +/** Returns a predicate for an unequal comparison against the supplied value |
| 61 | + @param value To compare against the attribute |
| 62 | + @return The predicate for this comparison |
| 63 | + @see notEqual:options: |
| 64 | + */ |
| 65 | +- (NSPredicate *)notEqual:(id)value; |
| 66 | + |
| 67 | +/** Returns a predicate for a like comparison against the supplied value |
| 68 | + @param value To compare against the attribute |
| 69 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 70 | + @return The predicate for this comparison |
| 71 | + @see like: |
| 72 | + */ |
| 73 | +- (NSPredicate *)like:(id)value options:(NSComparisonPredicateOptions)options; |
| 74 | + |
| 75 | +/** Returns a predicate for a like comparison against the supplied value |
| 76 | + @param value To compare against the attribute |
| 77 | + @return The predicate for this comparison |
| 78 | + @see like:options: |
| 79 | + */ |
| 80 | +- (NSPredicate *)like:(id)value; |
| 81 | + |
| 82 | +/** Returns a predicate for a matches comparison against the supplied value |
| 83 | + @param value To compare against the attribute |
| 84 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 85 | + @return The predicate for this comparison |
| 86 | + @see like: |
| 87 | + */ |
| 88 | +- (NSPredicate *)matches:(id)value options:(NSComparisonPredicateOptions)options; |
| 89 | + |
| 90 | +/** Returns a predicate for a matches comparison against the supplied value |
| 91 | + @param value To compare against the attribute |
| 92 | + @return The predicate for this comparison |
| 93 | + @see like:options: |
| 94 | + */ |
| 95 | +- (NSPredicate *)matches:(id)value; |
| 96 | + |
| 97 | +/** Returns a predicate for a begins with comparison against the supplied value |
| 98 | + @param value To compare against the attribute |
| 99 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 100 | + @return The predicate for this comparison |
| 101 | + @see like: |
| 102 | + */ |
| 103 | +- (NSPredicate *)beginsWith:(id)value options:(NSComparisonPredicateOptions)options; |
| 104 | + |
| 105 | +/** Returns a predicate for a begins with comparison against the supplied value |
| 106 | + @param value To compare against the attribute |
| 107 | + @return The predicate for this comparison |
| 108 | + @see like:options: |
| 109 | + */ |
| 110 | +- (NSPredicate *)beginsWith:(id)value; |
| 111 | + |
| 112 | +/** Returns a predicate for a ends with comparison against the supplied value |
| 113 | + @param value To compare against the attribute |
| 114 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 115 | + @return The predicate for this comparison |
| 116 | + @see like: |
| 117 | + */ |
| 118 | +- (NSPredicate *)endsWith:(id)value options:(NSComparisonPredicateOptions)options; |
| 119 | + |
| 120 | +/** Returns a predicate for a ends with comparison against the supplied value |
| 121 | + @param value To compare against the attribute |
| 122 | + @return The predicate for this comparison |
| 123 | + @see like:options: |
| 124 | + */ |
| 125 | +- (NSPredicate *)endsWith:(id)value; |
| 126 | + |
| 127 | +/** Returns a predicate for greater than the supplied value |
| 128 | + @param value To compare against the attribute |
| 129 | + @return The predicate for this comparison |
| 130 | + @see greaterThanOrEqualTo: |
| 131 | + */ |
| 132 | +- (NSPredicate *)greaterThan:(id)value; |
| 133 | + |
| 134 | +/** Returns a predicate for greater than or equal to the supplied value |
| 135 | + @param value To compare against the attribute |
| 136 | + @return The predicate for this comparison |
| 137 | + @see greaterThan: |
| 138 | + */ |
| 139 | +- (NSPredicate *)greaterThanOrEqualTo:(id)value; |
| 140 | + |
| 141 | +/** Returns a predicate for less than the supplied value |
| 142 | + @param value To compare against the attribute |
| 143 | + @return The predicate for this comparison |
| 144 | + @see lessThanOrEqualTo: |
| 145 | + */ |
| 146 | +- (NSPredicate *)lessThan:(id)value; |
| 147 | + |
| 148 | +/** Returns a predicate for less than or equal to the supplied value |
| 149 | + @param value To compare against the attribute |
| 150 | + @return The predicate for this comparison |
| 151 | + @see lessThan: |
| 152 | + */ |
| 153 | +- (NSPredicate *)lessThanOrEqualTo:(id)value; |
| 154 | + |
| 155 | +/** Returns a predicate for attribute being between two values |
| 156 | + @param minimumValue |
| 157 | + @param maximumValue |
| 158 | + @return The predicate for this comparison |
| 159 | + */ |
| 160 | +- (NSPredicate *)between:(id)minimumValue and:(id)maxiumValue; |
| 161 | + |
| 162 | +/** Returns an IN predicate for attribute |
| 163 | + @param set An enumerable object containing a set ob objects |
| 164 | + @return The predicate for this comparison |
| 165 | + */ |
| 166 | +- (NSPredicate *)in:(id<NSFastEnumeration>)set; |
| 167 | + |
| 168 | +/** Returns a predicate for a contains with comparison against the supplied value |
| 169 | + @param value To compare against the attribute |
| 170 | + @param options NSComparisonPredicateOptions to apply to the comparison |
| 171 | + @return The predicate for this comparison |
| 172 | + @see contains: |
| 173 | + */ |
| 174 | +- (NSPredicate *)contains:(id)value options:(NSComparisonPredicateOptions)options; |
| 175 | + |
| 176 | +/** Returns a predicate for a contains with comparison against the supplied value |
| 177 | + @param value To compare against the attribute |
| 178 | + @return The predicate for this comparison |
| 179 | + @see contains:options: |
| 180 | + */ |
| 181 | +- (NSPredicate *)contains:(id)value; |
| 182 | + |
| 183 | +/** Returns a predicate for if the attribute being equal to nil |
| 184 | + @return The predicate for the attribute being nil. |
| 185 | + */ |
| 186 | +- (NSPredicate *)isNil; |
| 187 | + |
| 188 | +/** Returns a predicate for if the attribute being equal to YES |
| 189 | + @return The predicate for the attribute being YES. |
| 190 | + @see isNO |
| 191 | + */ |
| 192 | +- (NSPredicate *)isYes; |
| 193 | + |
| 194 | +/** Returns a predicate for if the attribute being equal to NO |
| 195 | + @return The predicate for the attribute being NO. |
| 196 | + @see isYes |
| 197 | + */ |
| 198 | +- (NSPredicate *)isNo; |
| 199 | + |
| 200 | +@end |
| 201 | + |
| 202 | +@interface QKAttribute (Sorting) |
| 203 | + |
| 204 | +/** Returns an ascending sort descriptor for this attribute */ |
| 205 | +- (NSSortDescriptor *)ascending; |
| 206 | + |
| 207 | +/** Returns a descending sort descriptor for this attribute */ |
| 208 | +- (NSSortDescriptor *)descending; |
| 209 | + |
| 210 | +@end |
0 commit comments