Taxonomy
Taxonomy
Taxonomy helps you categorize pieces of content within your stack to facilitate easy navigation and retrieval of information.
initWithStack
The initWithStack method initializes a new instance of the Taxonomy class using the specified Stack.
| Name | Type | Description |
|---|---|---|
| stack (required) | String | The stack instance for making API requests |
Objective C:
Stack *stack = [Contentstack stackWithAPIKey:@"api_key"
deliveryToken:@"delivery_token"
environment:@"environment"];
Taxonomy *taxonomy = [[Taxonomy alloc] initWithStack:stack];Swift:
let stack = Contentstack.stack(apiKey: "api_key",
deliveryToken: "delivery_token",
environment: "environment")
let taxonomy = Taxonomy(stack: stack)query
The querymethod generates a new Query instance for the taxonomy.
Objective C:
Taxonomy *taxonomy = [[Taxonomy alloc] initWithStack:stack]; Query *query = [taxonomy query];
Swift:
let taxonomy = Taxonomy(stack: stack) let query = taxonomy.query()
whereKey:equalTo:
The whereKey:equalTo: method adds a condition to filter entries where the specified key matches the provided value.
| Name | Type | Description |
|---|---|---|
| key | NSString* | The key of the field to query for the desired data. |
| value | id | The value to match |
Objective C:
Taxonomy *taxonomy = [[Taxonomy alloc] initWithStack:stack]; Query *query = [taxonomy query]; [query whereKey:@"title" equalTo:@"Sample Taxonomy"];
Swift:
let taxonomy = Taxonomy(stack: stack)
let query = taxonomy.query()
query.whereKey("title", equalTo: "Sample Taxonomy")fetch:completion:
The whereKey:equalTo: method adds a condition to filter entries where the specified key matches the provided value.
| Name | Type | Description |
|---|---|---|
| params | NSDictionary<NSString*, id>* | Optional parameters for the request |
| completionBlock | Block | Completion handler with result or error |
Objective C:
NSDictionary *params = @{ @"include_count":@(true), @"include_global_field_schema": @(true) };
[taxonomy fetch:params completion:^(NSDictionary *entries, NSError *error) {
if (error)
{ NSLog(@"Error: %@", error.localizedDescription);
return;
}
NSLog(@"Fetched entries: %@", entries);
}];Swift:
let params = [ "include_count": true, "include_global_field_schema": true ] as [String : Any]
taxonomy.fetch(params) { (entries, error) in
if let error = error {
print("Error: \(error.localizedDescription)")
return }
if let entries = entries {
print("Fetched entries: \(entries)")
}
}findTaxonomy:
The findTaxonomy: method executes a query to fetch taxonomy entries that match specified query conditions.
| Name | Type | Description |
|---|---|---|
| completionBlock | completion | Returns (ResponseType, QueryResult*, NSError*) |
Objective C:
Query *query = [taxonomy query];
[query whereKey:@"taxonomies.one" equalTo:@"term_one"];
[query findTaxonomy:^(ResponseType type, QueryResult *result, NSError *error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
NSArray *entries = [result getResult];
NSLog(@"Fetched entries: %@", entries);
}];Swift:
let query = taxonomy.query()
query.whereKey("taxonomies.one", equalTo: "term_one")
query.findTaxonomy { (type, result, error) in
if let error = error {
print("Error: \(error.localizedDescription)")
return
}
if let entries = result?.getResult() {
print("Fetched entries: \(entries)")
}
}orWithSubqueries:
The orWithSubqueries method combines multiple queries using AND condition.
| Name | Type | Description |
|---|---|---|
| subqueries | NSArray<Query*>* | Array of Query objects to combine with OR |
Objective C:
Query *query1 = [taxonomy query]; [query1 whereKey:@"taxonomies.one" equalTo:@"term_one"]; Query *query2 =[taxonomy query]; [query2 whereKey:@"taxonomies.two" equalTo:@"term_two"]; Query *mainQuery = [taxonomy query]; [mainQuery orWithSubqueries:@[query1, query2]];
Swift:
let query1 = taxonomy.query()
query1.whereKey("taxonomies.one", equalTo: "term_one")
let query2 = taxonomy.query()
query2.whereKey("taxonomies.two", equalTo: "term_two")
let mainQuery = taxonomy.query()
mainQuery.orWithSubqueries([query1, query2])andWithSubqueries:
The andWithSubqueries: method combines multiple queries using AND condition.
| Name | Type | Description |
|---|---|---|
| subqueries | NSArray<Query*>* | Array of Query objects to combine with AND |
Objective C:
Query *query1 = [taxonomy query]; [query1 whereKey:@"taxonomies.one" equalTo:@"term_one"]; Query *query2 =[taxonomy query]; [query2 whereKey:@"taxonomies.two" equalTo:@"term_two"]; Query *mainQuery = [taxonomy query]; [mainQuery andWithSubqueries:@[query1, query2]];
Swift:
let query1 = taxonomy.query()
query1.whereKey("taxonomies.one", equalTo: "term_one")
let query2 = taxonomy.query()
query2.whereKey("taxonomies.two", equalTo: "term_two")
let mainQuery = taxonomy.query()
mainQuery.andWithSubqueries([query1, query2])