Skip to content

Commit 339a041

Browse files
committed
Provide QKAttribute, an Objective-C version of Attribute
This is mostly compatible with KFAttribute from KFData
1 parent 0911b40 commit 339a041

File tree

6 files changed

+658
-2
lines changed

6 files changed

+658
-2
lines changed

QueryKit.xcodeproj/project.pbxproj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
77A9B685195374490016654E /* QueryKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77A9B679195374490016654E /* QueryKit.framework */; };
1212
77A9B68C195374490016654E /* QueryKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A9B68B195374490016654E /* QueryKitTests.swift */; };
1313
77A9B698195374AA0016654E /* QueryKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A9B697195374AA0016654E /* QueryKit.swift */; };
14+
77B17B8519A94C9100D6540D /* QKAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 77B17B8319A94C9100D6540D /* QKAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
15+
77B17B8619A94C9100D6540D /* QKAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8419A94C9100D6540D /* QKAttribute.m */; };
16+
77B17B8819A94D2C00D6540D /* QKAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8719A94D2C00D6540D /* QKAttribute.swift */; };
17+
77B17B8B19A94D4C00D6540D /* QKAttributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */; };
1418
77E3A05D1969C019009372A8 /* QuerySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A05C1969C019009372A8 /* QuerySet.swift */; };
1519
77E3A05F1969C047009372A8 /* QuerySetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A05E1969C047009372A8 /* QuerySetTests.swift */; };
1620
77E3A0611969DDF5009372A8 /* Expression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A0601969DDF5009372A8 /* Expression.swift */; };
@@ -60,6 +64,10 @@
6064
77A9B68A195374490016654E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6165
77A9B68B195374490016654E /* QueryKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryKitTests.swift; sourceTree = "<group>"; };
6266
77A9B697195374AA0016654E /* QueryKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryKit.swift; sourceTree = "<group>"; };
67+
77B17B8319A94C9100D6540D /* QKAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKAttribute.h; sourceTree = "<group>"; };
68+
77B17B8419A94C9100D6540D /* QKAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKAttribute.m; sourceTree = "<group>"; };
69+
77B17B8719A94D2C00D6540D /* QKAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKAttribute.swift; sourceTree = "<group>"; };
70+
77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKAttributeTests.swift; sourceTree = "<group>"; };
6371
77E3A05C1969C019009372A8 /* QuerySet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySet.swift; sourceTree = "<group>"; };
6472
77E3A05E1969C047009372A8 /* QuerySetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySetTests.swift; sourceTree = "<group>"; };
6573
77E3A0601969DDF5009372A8 /* Expression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Expression.swift; sourceTree = "<group>"; };
@@ -116,6 +124,7 @@
116124
77E8728019539C0900A6F13F /* Attribute.swift */,
117125
77E3A0601969DDF5009372A8 /* Expression.swift */,
118126
77E8728619539FD200A6F13F /* Predicate.swift */,
127+
77B17B8219A94C9100D6540D /* ObjectiveC */,
119128
77A9B67C195374490016654E /* Supporting Files */,
120129
);
121130
path = QueryKit;
@@ -136,6 +145,7 @@
136145
77E3A05E1969C047009372A8 /* QuerySetTests.swift */,
137146
77E3A0621969E003009372A8 /* ExpressionTests.swift */,
138147
77E8728219539C2A00A6F13F /* AttributeTests.swift */,
148+
77B17B8919A94D4C00D6540D /* ObjectiveC */,
139149
77A9B689195374490016654E /* Supporting Files */,
140150
);
141151
path = QueryKitTests;
@@ -150,6 +160,24 @@
150160
name = "Supporting Files";
151161
sourceTree = "<group>";
152162
};
163+
77B17B8219A94C9100D6540D /* ObjectiveC */ = {
164+
isa = PBXGroup;
165+
children = (
166+
77B17B8319A94C9100D6540D /* QKAttribute.h */,
167+
77B17B8419A94C9100D6540D /* QKAttribute.m */,
168+
77B17B8719A94D2C00D6540D /* QKAttribute.swift */,
169+
);
170+
path = ObjectiveC;
171+
sourceTree = "<group>";
172+
};
173+
77B17B8919A94D4C00D6540D /* ObjectiveC */ = {
174+
isa = PBXGroup;
175+
children = (
176+
77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */,
177+
);
178+
path = ObjectiveC;
179+
sourceTree = "<group>";
180+
};
153181
/* End PBXGroup section */
154182

155183
/* Begin PBXHeadersBuildPhase section */
@@ -158,6 +186,7 @@
158186
buildActionMask = 2147483647;
159187
files = (
160188
77A9B67F195374490016654E /* QueryKit.h in Headers */,
189+
77B17B8519A94C9100D6540D /* QKAttribute.h in Headers */,
161190
);
162191
runOnlyForDeploymentPostprocessing = 0;
163192
};
@@ -262,6 +291,8 @@
262291
files = (
263292
77E8728119539C0900A6F13F /* Attribute.swift in Sources */,
264293
77E8728719539FD200A6F13F /* Predicate.swift in Sources */,
294+
77B17B8619A94C9100D6540D /* QKAttribute.m in Sources */,
295+
77B17B8819A94D2C00D6540D /* QKAttribute.swift in Sources */,
265296
77A9B698195374AA0016654E /* QueryKit.swift in Sources */,
266297
77E3A05D1969C019009372A8 /* QuerySet.swift in Sources */,
267298
77E3A0611969DDF5009372A8 /* Expression.swift in Sources */,
@@ -272,6 +303,7 @@
272303
isa = PBXSourcesBuildPhase;
273304
buildActionMask = 2147483647;
274305
files = (
306+
77B17B8B19A94D4C00D6540D /* QKAttributeTests.swift in Sources */,
275307
77E8728319539C2A00A6F13F /* AttributeTests.swift in Sources */,
276308
77A9B68C195374490016654E /* QueryKitTests.swift in Sources */,
277309
77E3A05F1969C047009372A8 /* QuerySetTests.swift in Sources */,

QueryKit/ObjectiveC/QKAttribute.h

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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

Comments
 (0)