Skip to content

Commit 733ade6

Browse files
committed
Merge pull request #13 from kylef/objectivec
Add support for bridging to Objective-C
2 parents 0911b40 + 427e6bd commit 733ade6

File tree

13 files changed

+1344
-3
lines changed

13 files changed

+1344
-3
lines changed

QueryKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Pod::Spec.new do |spec|
77
spec.author = { 'Kyle Fuller' => '[email protected]' }
88
spec.social_media_url = 'http://twitter.com/kylefuller'
99
spec.source = { :git => 'https://github.com/kylef/QueryKit.git', :tag => "#{spec.version}" }
10-
spec.source_files = 'QueryKit/*.{h,swift}'
10+
spec.source_files = 'QueryKit/*.{h}', 'QueryKit/ObjectiveC/*.{h,m}'
1111
spec.requires_arc = true
1212
end
1313

QueryKit.xcodeproj/project.pbxproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
77007D7D19A95CDE007DC2BC /* QKQuerySetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77007D7C19A95CDE007DC2BC /* QKQuerySetTests.swift */; };
11+
77007D8119A95CE9007DC2BC /* QKQuerySet.h in Headers */ = {isa = PBXBuildFile; fileRef = 77007D7E19A95CE9007DC2BC /* QKQuerySet.h */; settings = {ATTRIBUTES = (Public, ); }; };
12+
77007D8219A95CE9007DC2BC /* QKQuerySet.m in Sources */ = {isa = PBXBuildFile; fileRef = 77007D7F19A95CE9007DC2BC /* QKQuerySet.m */; };
13+
77007D8319A95CE9007DC2BC /* QKQuerySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77007D8019A95CE9007DC2BC /* QKQuerySet.swift */; };
14+
775E2A1B19B4981E007FE5BA /* QKQuerySetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 775E2A1A19B4981E007FE5BA /* QKQuerySetTests.m */; };
1015
77A9B67F195374490016654E /* QueryKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 77A9B67E195374490016654E /* QueryKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
1116
77A9B685195374490016654E /* QueryKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77A9B679195374490016654E /* QueryKit.framework */; };
1217
77A9B68C195374490016654E /* QueryKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A9B68B195374490016654E /* QueryKitTests.swift */; };
1318
77A9B698195374AA0016654E /* QueryKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A9B697195374AA0016654E /* QueryKit.swift */; };
19+
77B17B8519A94C9100D6540D /* QKAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 77B17B8319A94C9100D6540D /* QKAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
20+
77B17B8619A94C9100D6540D /* QKAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8419A94C9100D6540D /* QKAttribute.m */; };
21+
77B17B8819A94D2C00D6540D /* QKAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8719A94D2C00D6540D /* QKAttribute.swift */; };
22+
77B17B8B19A94D4C00D6540D /* QKAttributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */; };
1423
77E3A05D1969C019009372A8 /* QuerySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A05C1969C019009372A8 /* QuerySet.swift */; };
1524
77E3A05F1969C047009372A8 /* QuerySetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A05E1969C047009372A8 /* QuerySetTests.swift */; };
1625
77E3A0611969DDF5009372A8 /* Expression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E3A0601969DDF5009372A8 /* Expression.swift */; };
@@ -53,13 +62,23 @@
5362
/* End PBXContainerItemProxy section */
5463

5564
/* Begin PBXFileReference section */
65+
77007D7C19A95CDE007DC2BC /* QKQuerySetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKQuerySetTests.swift; sourceTree = "<group>"; };
66+
77007D7E19A95CE9007DC2BC /* QKQuerySet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKQuerySet.h; sourceTree = "<group>"; };
67+
77007D7F19A95CE9007DC2BC /* QKQuerySet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuerySet.m; sourceTree = "<group>"; };
68+
77007D8019A95CE9007DC2BC /* QKQuerySet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKQuerySet.swift; sourceTree = "<group>"; };
69+
775E2A1919B4981D007FE5BA /* QueryKitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "QueryKitTests-Bridging-Header.h"; sourceTree = "<group>"; };
70+
775E2A1A19B4981E007FE5BA /* QKQuerySetTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKQuerySetTests.m; sourceTree = "<group>"; };
5671
77A9B679195374490016654E /* QueryKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = QueryKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5772
77A9B67D195374490016654E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5873
77A9B67E195374490016654E /* QueryKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QueryKit.h; sourceTree = "<group>"; };
5974
77A9B684195374490016654E /* QueryKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QueryKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6075
77A9B68A195374490016654E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6176
77A9B68B195374490016654E /* QueryKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryKitTests.swift; sourceTree = "<group>"; };
6277
77A9B697195374AA0016654E /* QueryKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryKit.swift; sourceTree = "<group>"; };
78+
77B17B8319A94C9100D6540D /* QKAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QKAttribute.h; sourceTree = "<group>"; };
79+
77B17B8419A94C9100D6540D /* QKAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QKAttribute.m; sourceTree = "<group>"; };
80+
77B17B8719A94D2C00D6540D /* QKAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKAttribute.swift; sourceTree = "<group>"; };
81+
77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QKAttributeTests.swift; sourceTree = "<group>"; };
6382
77E3A05C1969C019009372A8 /* QuerySet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySet.swift; sourceTree = "<group>"; };
6483
77E3A05E1969C047009372A8 /* QuerySetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySetTests.swift; sourceTree = "<group>"; };
6584
77E3A0601969DDF5009372A8 /* Expression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Expression.swift; sourceTree = "<group>"; };
@@ -116,6 +135,7 @@
116135
77E8728019539C0900A6F13F /* Attribute.swift */,
117136
77E3A0601969DDF5009372A8 /* Expression.swift */,
118137
77E8728619539FD200A6F13F /* Predicate.swift */,
138+
77B17B8219A94C9100D6540D /* ObjectiveC */,
119139
77A9B67C195374490016654E /* Supporting Files */,
120140
);
121141
path = QueryKit;
@@ -136,6 +156,7 @@
136156
77E3A05E1969C047009372A8 /* QuerySetTests.swift */,
137157
77E3A0621969E003009372A8 /* ExpressionTests.swift */,
138158
77E8728219539C2A00A6F13F /* AttributeTests.swift */,
159+
77B17B8919A94D4C00D6540D /* ObjectiveC */,
139160
77A9B689195374490016654E /* Supporting Files */,
140161
);
141162
path = QueryKitTests;
@@ -150,6 +171,30 @@
150171
name = "Supporting Files";
151172
sourceTree = "<group>";
152173
};
174+
77B17B8219A94C9100D6540D /* ObjectiveC */ = {
175+
isa = PBXGroup;
176+
children = (
177+
77B17B8319A94C9100D6540D /* QKAttribute.h */,
178+
77B17B8419A94C9100D6540D /* QKAttribute.m */,
179+
77B17B8719A94D2C00D6540D /* QKAttribute.swift */,
180+
77007D7E19A95CE9007DC2BC /* QKQuerySet.h */,
181+
77007D7F19A95CE9007DC2BC /* QKQuerySet.m */,
182+
77007D8019A95CE9007DC2BC /* QKQuerySet.swift */,
183+
);
184+
path = ObjectiveC;
185+
sourceTree = "<group>";
186+
};
187+
77B17B8919A94D4C00D6540D /* ObjectiveC */ = {
188+
isa = PBXGroup;
189+
children = (
190+
775E2A1919B4981D007FE5BA /* QueryKitTests-Bridging-Header.h */,
191+
77B17B8A19A94D4C00D6540D /* QKAttributeTests.swift */,
192+
775E2A1A19B4981E007FE5BA /* QKQuerySetTests.m */,
193+
77007D7C19A95CDE007DC2BC /* QKQuerySetTests.swift */,
194+
);
195+
path = ObjectiveC;
196+
sourceTree = "<group>";
197+
};
153198
/* End PBXGroup section */
154199

155200
/* Begin PBXHeadersBuildPhase section */
@@ -158,6 +203,8 @@
158203
buildActionMask = 2147483647;
159204
files = (
160205
77A9B67F195374490016654E /* QueryKit.h in Headers */,
206+
77B17B8519A94C9100D6540D /* QKAttribute.h in Headers */,
207+
77007D8119A95CE9007DC2BC /* QKQuerySet.h in Headers */,
161208
);
162209
runOnlyForDeploymentPostprocessing = 0;
163210
};
@@ -262,7 +309,11 @@
262309
files = (
263310
77E8728119539C0900A6F13F /* Attribute.swift in Sources */,
264311
77E8728719539FD200A6F13F /* Predicate.swift in Sources */,
312+
77B17B8619A94C9100D6540D /* QKAttribute.m in Sources */,
313+
77B17B8819A94D2C00D6540D /* QKAttribute.swift in Sources */,
265314
77A9B698195374AA0016654E /* QueryKit.swift in Sources */,
315+
77007D8319A95CE9007DC2BC /* QKQuerySet.swift in Sources */,
316+
77007D8219A95CE9007DC2BC /* QKQuerySet.m in Sources */,
266317
77E3A05D1969C019009372A8 /* QuerySet.swift in Sources */,
267318
77E3A0611969DDF5009372A8 /* Expression.swift in Sources */,
268319
);
@@ -272,9 +323,12 @@
272323
isa = PBXSourcesBuildPhase;
273324
buildActionMask = 2147483647;
274325
files = (
326+
77B17B8B19A94D4C00D6540D /* QKAttributeTests.swift in Sources */,
275327
77E8728319539C2A00A6F13F /* AttributeTests.swift in Sources */,
276328
77A9B68C195374490016654E /* QueryKitTests.swift in Sources */,
329+
77007D7D19A95CDE007DC2BC /* QKQuerySetTests.swift in Sources */,
277330
77E3A05F1969C047009372A8 /* QuerySetTests.swift in Sources */,
331+
775E2A1B19B4981E007FE5BA /* QKQuerySetTests.m in Sources */,
278332
77E8728519539FC000A6F13F /* PredicateTests.swift in Sources */,
279333
77E3A0631969E003009372A8 /* ExpressionTests.swift in Sources */,
280334
);
@@ -466,6 +520,7 @@
466520
ONLY_ACTIVE_ARCH = YES;
467521
PRODUCT_NAME = "$(TARGET_NAME)";
468522
SDKROOT = macosx;
523+
SWIFT_OBJC_BRIDGING_HEADER = "QueryKitTests/ObjectiveC/QueryKitTests-Bridging-Header.h";
469524
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
470525
};
471526
name = Debug;
@@ -509,6 +564,7 @@
509564
METAL_ENABLE_DEBUG_INFO = NO;
510565
PRODUCT_NAME = "$(TARGET_NAME)";
511566
SDKROOT = macosx;
567+
SWIFT_OBJC_BRIDGING_HEADER = "QueryKitTests/ObjectiveC/QueryKitTests-Bridging-Header.h";
512568
};
513569
name = Release;
514570
};

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;
20+
21+
/// Initialized the attribute with the given name
22+
- (instancetype)initWithName:(NSString *)name __attribute((nonnull));
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)