Getting a Subset of Fields

Getting a Subset of Fields

When you read data from Telerik Platform, you can choose to receive only a subset of all available fields for each item. This saves bandwidth and can improve your app performance because data is fetched from the server faster. By default, all fields are returned from the server.

Specifics

The Id field is always returned by the server. In order to omit it you need to exclude it explicitly from the projection.

You cannot use inclusion and exclusion definitions simultaneously.

Including fields

To project only a subset of fields to the response, you need to add the included fields to a NSArray and pass the array to the setSubsetOfFields method of the request. Then, you need to pass IncludeSubsetFields to the setFieldInclusionMode method of the request.

The following method will return only the specified fields:

EVFetchRequest *request = [EVFetchRequest fetchRequestWithKindOfClass:[Activities class]];
[request setSubsetOfFields:[[NSArray alloc] initWithObjects:@"Rating",@"Text", nil]];
[request setFieldsInclusionMode:IncludeSubsetFields];

[dataStore executeFetchRequest:request block:^(NSArray *result, NSError *error) {
    // The retrieved items will have only Rating and Text fields                
}];

Excluding Fields

Alternatively, you can specify which fields to exclude, by adding the included fields to a NSArray and pass the array to the setSubsetOfFields method of the request. Then, you need to pass ExcludeSubsetFields to the setFieldInclusionMode method of the request.

The following method will return all, but the specified fields.

EVFetchRequest *request = [EVFetchRequest fetchRequestWithKindOfClass:[Activities class]];
[request setSubsetOfFields:[[NSArray alloc] initWithObjects:@"Rating",@"Text", nil]];
[request setFieldsInclusionMode:ExcludeSubsetFields];

[dataStore executeFetchRequest:request block:^(NSArray *result, NSError *error) {
    // The retrieved items won't have Rating and Text fields                
}];
Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.