Query Class Reference
Inherits from | NSObject |
---|---|
Declared in | Query.h |
Properties
cachePolicy
property to assign cache policy like CACHE_THEN_NETWORK, NETWORK_ELSE_CACHE, NETWORK_ONLY, etc.
@property (nonatomic, assign) CachePolicy cachePolicy
Declared In
Query.h
Manually set headers
– setHeader:forKey:
Set a header for an query
- (void)setHeader:(NSString *)headerValue forKey:(NSString *)headerKey
Parameters
headerValue |
The header key |
---|---|
headerKey |
The header value |
Discussion
//Obj-C
Query *blogQuery = [contentTypeObj query];
[blogQuery setHeader:@"MyHeaderValue" forKey:@"My-Custom-Header-Key"];
//Swift
var blogQuery:Query = contentTypeObj.query()
blogQuery.setHeader("MyHeaderValue", forKey:"My-Custom-Header-Key")
Declared In
Query.h
– addHeadersWithDictionary:
Set a header for an query
- (void)addHeadersWithDictionary:(NSDictionary<NSString*,NSString*> *)headers
Parameters
headers |
The headers as dictionary which needs to be added to the application |
---|
Discussion
//Obj-C
Query *blogQuery = [contentTypeObj query];
[blogQuery addHeadersWithDictionary:@{@"My-Custom-Header-Key":@"MyHeaderValue"}];
//Swift
var blogQuery:Query = contentTypeObj.query()
blogQuery.addHeadersWithDictionary(["My-Custom-Header-Key":"MyHeaderValue"])
Declared In
Query.h
– removeHeaderForKey:
Removes a header from this query.
- (void)removeHeaderForKey:(NSString *)headerKey
Parameters
headerKey |
The header key that needs to be removed |
---|
Discussion
//Obj-C
Query *blogQuery = [contentTypeObj query];
[blogQuery removeHeaderForKey:@"My-Custom-Header-Key"];
//Swift
var blogQuery:Query = contentTypeObj.query()
blogQuery.removeHeaderForKey("My-Custom-Header-Key")
Declared In
Query.h
Language
– language:
This method provides all the entries for the specified language in the response.
- (void)language:(Language)language
Parameters
language |
Language enum for all language available. |
---|
Discussion
//Obj-C
[blogQuery language:ENGLISH_UNITED_STATES];
//Swift
blogQuery.language(Language.ENGLISH_UNITED_STATES)
Declared In
Query.h
Search
– search:
This method provides only the entries matching the specified value.
- (void)search:(NSString *)searchString
Parameters
searchString |
The value used to match or compare |
---|
Discussion
//Obj-C
[blogQuery search:@"header"];
//Swift
blogQuery.search(@"header")
Declared In
Query.h
Tags
– tags:
This method provides only the entries that contain tags matching the ones mentioned in the function.
- (void)tags:(NSArray<NSString*> *)tagsArray
Parameters
tagsArray |
An array of tags that are to be included for the key |
---|
Discussion
//Obj-C
[blogQuery tags:@[@"phone", @"laptop"]];
//Swift
blogQuery.tags(["phone", "laptop"])
Declared In
Query.h
Subqueries with AND / OR
– orWithSubqueries:
This method performs the OR operation on the specified query objects and provides only the matching entries.
- (void)orWithSubqueries:(NSArray<Query*> *)queries
Parameters
queries |
Array of queries to be taken into consideration |
---|
Discussion
//Obj-C
Query *query1 = [contentTypeObj query];
[query1 whereKey:@"title" equalTo:@"Welcome"];
Query *query2 = [contentTypeObj query];
[query2 whereKey:@"introduction" equalTo:@"This is Test"];
[blogQuery orWithSubqueries:@[query1, query2]];
//Swift
var query1:Query = contentTypeObj.query()
query1.whereKey("title", equalTo:"Welcome")
var query2:Query = contentTypeObj.query()
query2.whereKey("introduction", equalTo:"This is Test")
blogQuery.orWithSubqueries([query1, query2])
Declared In
Query.h
– andWithSubqueries:
This method performs the AND operation on the specified query objects and provides only the matching entries.
- (void)andWithSubqueries:(NSArray<Query*> *)queries
Parameters
queries |
Array of queries to be taken into consideration |
---|
Discussion
//Obj-C
Query *query1 = [contentTypeObj query];
[query1 whereKey:@"total_hits" greaterThanOrEqualTo:@(800)];
Query *query2 = [contentTypeObj query];
[query2 whereKey:@"total_hits" lessThanOrEqualTo:@(1200)];
[blogQuery andWithSubqueries:@[query1, query2]];
//Swift
var query1:Query = contentTypeObj.query()
query1.whereKey("total_hits", greaterThanOrEqualTo:800)
var query2:Query = contentTypeObj.query()
query2.whereKey("total_hits", equalTo:1200)
blogQuery.andWithSubqueries([query1, query2])
Declared In
Query.h
Sorting
– orderByAscending:
Sorts the provided entries in the ascending order on the basis of the specified field.
- (void)orderByAscending:(NSString *)key
Parameters
key |
field uid based on which the ordering should be done. |
---|
Discussion
//Obj-C
[blogQuery orderByAscending:@"updated_at"];
//Swift
blogQuery.orderByAscending("updated_at")
Declared In
Query.h
– orderByDescending:
Sorts the provided entries in the descending order on the basis of the specified field.
- (void)orderByDescending:(NSString *)key
Parameters
key |
field uid based on which the ordering should be done. |
---|
Discussion
//Obj-C
[blogQuery orderByDescending:@"updated_at"];
//Swift
blogQuery.orderByDescending("updated_at")
Declared In
Query.h
Include
– objectsCount
Provides only the number of entries with values matching the specified values for a field.
- (void)objectsCount
Discussion
//Obj-C
[blogQuery objectsCount];
//Swift
blogQuery.objectsCount()
Declared In
Query.h
– includeContentType
This method also includes the contenttype for the entries returned in the response.
- (void)includeContentType
Discussion
//Obj-C
[blogQuery includeContentType];
//Swift
blogQuery.includeContentType()
Declared In
Query.h
– includeFallback
Retrieve the published content of the fallback locale entry if the entry is not localized in specified locale.
- (void)includeFallback
Discussion
//Obj-C
[blogQuery includeFallback];
//Swift
blogQuery.includeFallback()
Declared In
Query.h
– includeReferenceContentTypeUid
This method also includes the content type UIDs of the referenced entries returned in the response.
- (void)includeReferenceContentTypeUid
Discussion
//Obj-C
[blogQuery includeReferenceContentTypeUid];
//Swift
blogQuery.includeReferenceContentTypeUid()
Declared In
Query.h
– includeOwner
This method also includes owner information for all the entries returned in the response.
- (void)includeOwner
Discussion
//Obj-C
[blogQuery includeOwner];
//Swift
blogQuery.includeOwner()
Declared In
Query.h
– includeCount
This method also includes the total number of entries returned in the response.
- (void)includeCount
Discussion
//Obj-C
[blogQuery includeCount];
//Swift
blogQuery.includeCount()
Declared In
Query.h
Pagination
– limitObjects:
This method limits the response by providing only the specified number of entries.
- (void)limitObjects:(NSNumber *)number
Parameters
number |
Number of entries to be returned |
---|
Discussion
//Obj-C
[blogQuery limitObjects:@(5)];
//Swift
blogQuery.limitObjects(NSNumber(int:5))
Declared In
Query.h
– skipObjects:
This method limits the response by providing only the specified number of entries.
- (void)skipObjects:(NSNumber *)number
Parameters
number |
Number of entries to be returned |
---|
Discussion
//Obj-C
[blogQuery skipObjects:@(5)];
//Swift
blogQuery.skipObjects(NSNumber(int:5))
Declared In
Query.h
Adding Basic Constraints
– addQueryWithKey:andValue:
Include custom query using a key and a value.
- (void)addQueryWithKey:(NSString *)key andValue:(id)value
Parameters
key |
name of the query. |
---|---|
value |
value for the query. |
Discussion
//Obj-C
[blogQuery addQueryWithKey:@"key_name" andValue:@"MyValue"];
//Swift
blogQuery.addQueryWithKey("key_name", andValue:"MyValue")
Include custom query using a key and a value.
Declared In
Query.h
– addQueryParams:
A custom dictionary can be provided to a query that can specify the conditions for retrieving objects.
- (void)addQueryParams:(NSDictionary<NSString*,id> *)queryDict
Parameters
queryDict |
A dictionary with all the necessary conditions for retrieving objects. |
---|
Discussion
//Obj-C
[blogQuery addQueryParams:@{@"Query_Key":@"Query Value"}];
//Swift
blogQuery.addQueryParams(["Query_Key":"Query Value"])
If a complex query needs to be performed and if it is difficult to specify it using the query methods, a dictionary can be provided that specifies all the conditions. The dictionary should be as per the JSON format specified in the REST API docs.
Declared In
Query.h
– removeQueryWithKey:
Removes custom query.
- (void)removeQueryWithKey:(NSString *)key
Parameters
key |
name of the query. |
---|
Discussion
//Obj-C
[blogQuery removeQueryWithKey:@"Query_Key"];
//Swift
blogQuery.removeQueryWithKey("Query_Key")
Declared In
Query.h
– whereKey:equalTo:
This method provides only the entries matching the specified value for a field.
- (void)whereKey:(NSString *)key equalTo:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"title" equalTo:@"Welcome"];
//Swift
blogQuery.whereKey("title", equalTo:"Welcome")
Declared In
Query.h
– whereKey:notEqualTo:
This method provides only the entries with values not equal to the specified value for a field.
- (void)whereKey:(NSString *)key notEqualTo:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"title" notEqualTo:@"Welcome"];
//Swift
blogQuery.whereKey("title", notEqualTo:"Welcome")
Declared In
Query.h
– whereKey:lessThan:
This method provides only the entries with a values less than the specified value for a field.
- (void)whereKey:(NSString *)key lessThan:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"created_at" lessThan:@"2015-06-22"];
//Swift
blogQuery.whereKey("created_at", lessThan:"2015-06-22")
Declared In
Query.h
– whereKey:greaterThan:
This method provides only the entries with values greater than the specified value for a field.
- (void)whereKey:(NSString *)key greaterThan:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"created_at" greaterThan:@"2015-03-12"];
//Swift
blogQuery.whereKey("created_at", greaterThan:"2015-03-12")
Declared In
Query.h
– whereKey:lessThanOrEqualTo:
This method provides only the entries with values less than or equal to the specified value for a field.
- (void)whereKey:(NSString *)key lessThanOrEqualTo:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"created_at" lessThanOrEqualTo:@"2015-03-12"];
//Swift
blogQuery.whereKey("created_at", lessThanOrEqualTo:"2015-03-12")
Declared In
Query.h
– whereKey:greaterThanOrEqualTo:
This method provides only the entries with values greater than or equal to the specified value for a field.
- (void)whereKey:(NSString *)key greaterThanOrEqualTo:(id)object
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
object |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"created_at" greaterThanOrEqualTo:@"2015-03-12"];
//Swift
blogQuery.whereKey("created_at", greaterThanOrEqualTo:"2015-03-12")
Declared In
Query.h
– whereKey:containedIn:
This method provides only the entries with values matching the specified values for a field.
- (void)whereKey:(NSString *)key containedIn:(NSArray *)array
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
array |
An array of values that are to be used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"title" containedIn:@["Demo", @"Welcome"]];
//Swift
blogQuery.whereKey("title", containedIn:["Demo", "Welcome"])
Declared In
Query.h
– whereKey:notContainedIn:
This method provides only the entries that do not contain values matching the specified values for a field.
- (void)whereKey:(NSString *)key notContainedIn:(NSArray *)array
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
array |
An array of values that are to be used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"title" notContainedIn:@["Demo", @"Welcome"]];
//Swift
blogQuery.whereKey("title", notContainedIn:["Demo", "Welcome"])
Declared In
Query.h
– whereKeyExists:
This method provides only the entries that contains the field matching the specified field uid.
- (void)whereKeyExists:(NSString *)key
Parameters
key |
Uid of the field that is to be taken into consideration |
---|
Discussion
//Obj-C
[blogQuery whereKeyExists:@"introduction"];
//Swift
blogQuery.whereKeyExists("introduction")
Declared In
Query.h
– whereKeyDoesNotExist:
This method provides only the entries that do not contain the field matching the specified field uid.
- (void)whereKeyDoesNotExist:(NSString *)key
Parameters
key |
Uid of the field that is to be taken into consideration |
---|
Discussion
//Obj-C
[blogQuery whereKeyDoesNotExist:@"introduction"];
//Swift
blogQuery.whereKeyDoesNotExist("introduction")
Declared In
Query.h
– whereKey:matchesRegex:
This method provides only the entries matching the regular expression for the specified field.
- (void)whereKey:(NSString *)key matchesRegex:(NSString *)regex
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
regex |
The value used to match or compare |
Discussion
//Obj-C
[blogQuery whereKey:@"title" matchesRegex:@"^wel"];
//Swift
blogQuery.whereKey("title", matchesRegex:"^wel")
Declared In
Query.h
– whereKey:matchesRegex:modifiers:
This method provides only the entries matching the regular expression for the specified field.
- (void)whereKey:(NSString *)key matchesRegex:(NSString *)regex modifiers:(NSString *)modifier
Parameters
key |
Uid of the field that is to be taken into consideration |
---|---|
regex |
The value used to match or compare |
modifier |
Modifiers for regex options. Specify ‘i’ as the option to ignore the case. |
Discussion
//Obj-C
[blogQuery whereKey:@"title" matchesRegex:@"^wel" modifiers:@"i"];
//Swift
blogQuery.whereKey("title", matchesRegex:"^wel", modifiers:"i")
Declared In
Query.h
– whereKey:in:
This method provides only the entries matching the Query. //Obj-C Query *reference = [contentTypeObj query]; [reference whereKey:@“name” equalTo:@“Author”];
- (void)whereKey:(NSString *)key in:(Query *)query
Parameters
key |
Reference Uid of the field that is to be taken into consideration |
---|---|
query |
Querie to be taken into consideration |
Discussion
[blogQuery whereKey:@"author" in:reference];
//Swift
var reference:Query = contentTypeObj.query()
reference.whereKey("name", equalTo:@"Author")
blogQuery.whereKey("author", in:reference)
Declared In
Query.h
– whereKey:notIn:
This method provides only the entries matching the Query. //Obj-C Query *reference = [contentTypeObj query]; [reference whereKey:@“name” equalTo:@“Author”];
- (void)whereKey:(NSString *)key notIn:(Query *)query
Parameters
key |
Reference Uid of the field that is to be taken into consideration |
---|---|
query |
Querie to be taken into consideration |
Discussion
[blogQuery whereKey:@"author" notIn:reference];
//Swift
var reference:Query = contentTypeObj.query()
reference.whereKey("name", equalTo:@"Author")
blogQuery.whereKey("author", notIn:reference)
Declared In
Query.h
Selective fields using only/except
– onlyFields:
This method provides only the entries that match the specified field uids and corresponding values.
- (void)onlyFields:(NSArray<NSString*> *)fieldUIDs
Parameters
fieldUIDs |
An array of values that are to be included for the key |
---|
Discussion
//Obj-C
[blogQuery onlyFields:@[@"attachments"]];
//Swift
blogQuery.onlyFields(["attachments"])
Declared In
Query.h
– exceptFields:
This method provides all entries except those that match the specified field uids and corresponding values.
- (void)exceptFields:(NSArray<NSString*> *)fieldUIDs
Parameters
fieldUIDs |
An array of values that are to be included for the key |
---|
Discussion
//Obj-C
[blogQuery exceptFields:@[@"attachments"]];
//Swift
blogQuery.exceptFields(["attachments"])
Declared In
Query.h
Reference Query (Query Conditions on Reference fields)
– includeReferenceFieldWithKey:
This method provides all entries that also contain data from the referred entry in the specified field.
- (void)includeReferenceFieldWithKey:(NSArray<NSString*> *)key
Parameters
key |
Uid of the reference field that is to be taken into consideration |
---|
Discussion
//Obj-C
[blogQuery includeReferenceFieldWithKey:@"entry_a"];
//Swift
blogQuery.includeReferenceFieldWithKey(@"entry_a")
Declared In
Query.h
– includeReferenceFieldWithKey:onlyFields:
This method provides all entries incuding referred entry containing only specified fields.
- (void)includeReferenceFieldWithKey:(NSString *)key onlyFields:(NSArray<NSString*> *)fieldUIDs
Parameters
key |
Uid of the reference field that is to be taken into consideration |
---|---|
fieldUIDs |
Uid of the reference field that is to be taken into consideration |
Discussion
//Obj-C
[blogQuery includeReferenceFieldWithKey:@"reference_field_uid" onlyFields:@[@"attachments"]];
//Swift
blogQuery.includeReferenceFieldWithKey(@"reference_field_uid", onlyFields:["attachments"])
Declared In
Query.h
– includeReferenceFieldWithKey:excludingFields:
This method provides all entries incuding referred entry containing all fields except specified fields.
- (void)includeReferenceFieldWithKey:(NSString *)key excludingFields:(NSArray<NSString*> *)fieldUIDs
Parameters
key |
Uid of the reference field that is to be taken into consideration |
---|---|
fieldUIDs |
Uid of the reference field that is to be taken into consideration |
Discussion
//Obj-C
[blogQuery includeReferenceFieldWithKey:@"entry_a" excludingFields:@[@"attachments"]];
//Swift
blogQuery.includeReferenceFieldWithKey(@"entry_a", excludingFields:["attachments"])
Declared In
Query.h
– addParamKey:andValue:
This method adds key and value to a query.
- (void)addParamKey:(NSString *)key andValue:(NSString *)value
Parameters
key |
The key as string which needs to be added to the Query |
---|---|
value |
The value as string which needs to be added to the Query |
Discussion
//Obj-C
Query *blogQuery = [contentTypeObj query];
[blogQuery addParamKey:@"key" andValue:@"value"];
//Swift
var blogQuery:Query = contentTypeObj.query()
blogQuery.addParamKey("key", andValue:"value")
Declared In
Query.h
Execute Query
– find:
This method provides all the entries from a specified contenttype.
- (void)find:(void ( ^ ) ( ResponseType type , QueryResult *BUILT_NULLABLE_P result , NSError *BUILT_NULLABLE_P error ))completionBlock
Parameters
completionBlock |
block to be called once operation is done. The result data contains all entries of the specified contenttype. |
---|
Discussion
//Obj-C
[blogQuery find:^(ResponseType type, QueryResult *result, NSError *error) {
//error for any error description
//result for reponse data
}];
//Swift
blogQuery.find { (responseType, result!, error!) -> Void in
//error for any error description
//result for reponse data
}
Declared In
Query.h
– findOne:
This method provides the first entry from a specified contenttype.
- (void)findOne:(void ( ^ ) ( ResponseType type , Entry *BUILT_NULLABLE_P entry , NSError *BUILT_NULLABLE_P error ))completionBlock
Parameters
completionBlock |
block to be called once operation is done. |
---|
Discussion
//Obj-C
[blogQuery findOne:^(ResponseType type, Entry *entry, NSError *error) {
//error for any error description
//result for reponse data
}];
//Swift
blogQuery.findOne { (responseType, entry!, error!) -> Void in
//error for any error description
//result for reponse data
}
Declared In
Query.h
Cancel execution
– cancelRequests
Advises the operation object that it should stop executing its task.
//Obj-C
[blogQuery cancelRequests];
//Swift
blogQuery.cancelRequests()
- (void)cancelRequests
Discussion
This method does not force your operation code to stop. Instead, it updates the object’s internal flags to reflect the change in state. If the operation has already finished executing, this method has no effect. Canceling an operation that is currently in an operation queue, but not yet executing, makes it possible to remove the operation from the queue sooner than usual.
Declared In
Query.h