DACalculatedFieldDefinition

Overview

DACalculatedFieldDefinition is a specialization of the general DAFieldDefinition class, and represents a field for which the value is not stored directly in the DADataTable, but calculated, at runtime. In contrast to DALookupFieldDefinitions, which obtain their value automatically by referring to another table, calculated fields depend on the developer to provide custom code that determines the value of the field, as needed. For this, a selector and a target object are assigned to the calculated field, with the selector identifying the name of the custom method that provides the implementation, and the target identifying the object that implements this selector.

The calculation method must be defined to take one parameter, a DADataTableRow, and return id or an object matching the dataType configured for the field. When called, the row parameter will provide access to the row that the value should be calculated for. No reference to the calculated field is provided, so a class that is meant to provide values for multiple calculated fields will need to provide distinct methods for each.

DACalculatedFieldDefinitions can be created either by calling addCalculatedFieldName:dataType:target:selector: on the DADataTable, or by manually creating an instance and passing it to addCalculatedField:.

Calculated fields can be seen in action in the Field Types sample.

Location

 

dataType    (declared in DAFieldDefinition)

Specifies the Data Type for the field.

@property (readonly) enum DADataType dataType

dataTypeName    (declared in DAFieldDefinition)

Returns the readable name of the fields data type, as defined by the dataType property.

@property (readonly) NSString *dataTypeName

initWithDataTable:name:dataType:target:selector:

Initializes a new instance of a calculated field.

- (id) initWithDataTable:(DADataTable *)ownerTable name:(NSString *)fieldName dataType:(enum DADataType)dataType target:(id)target selector:(SEL)selector

Parameters:

  • ownerTable: Specifies the DADataTable this field will be defined for.
  • fieldName: Specifies the unique name of this field within the data table.
  • dataType: Specifies the Data Type for the newly calculated field.
  • target: Specifies the object that implements the calculation method identified by the selector.
  • selector: Specifies the selector identifying the method on the target that will calculate the value for this field.

initWithTable:    (declared in DAFieldDefinition)

Initializes new DAFieldDefinition instance with given data table

- (id) initWithTable:(DADataTable *)ownerTable

Parameters:


initWithTable:name:    (declared in DAFieldDefinition)

Initializes a new DAFieldDefinition instance with given data table and field name.

- (id) initWithTable:(DADataTable *)ownerTable name:(NSString *)fieldName

Parameters:

  • ownerTable:
  • fieldName:

name    (declared in DAFieldDefinition)

Specifies the uniqe name of the field within the data table. The field can be queried by this name using KVC's valueForKey: and setValue:forKey: methods on the individual DADataTableRows.

@property (readonly) NSString *name

position    (declared in DAFieldDefinition)

Returns the position or index of the field within the data table. This is mainly for internal use; regular field access should use the name and not rely on position.

@property (readonly) NSInteger position

predicateEditorRowTemplates    (declared in DAFieldDefinition)

Returns an array with one or more NSPredicateEditorRowTemplates that match the field definition, for use in an NSPredicateEditor. Usually, you will not call 'send this message' to an individual field, but use the DADataTable's defaultPredicateEditorRowTemplates method. See also Working with NSPredicateEditor (Xcode (Mac)).

- (NSArray *) predicateEditorRowTemplates

properties    (declared in DAFieldDefinition)

Provides access to various properties of the field as defined in the server's Schema.

@property (readonly) NSDictionary *properties

selector

Specifies the object that implements the calculation method identified by the selector.

@property (readonly) SEL selector

setProperty:toValue:    (declared in DAFieldDefinition)

Updates a property stored in the properties list.

- (void) setProperty:(NSString *)propertyName toValue:(NSString *)propertyValue

Parameters:

  • propertyName: name of the property for which we want to set new value
  • propertyValue: new value we want to set.

table    (declared in DAFieldDefinition)

Returns a reference to the DADataTable that contains this field.

@property (readonly) DADataTable *table

target

Specifies the selector identifying the method on the target that will calculate the value for this field.

@property (readonly) id target

valueForRow:

For internal use, returns the calculated value for a given row, by performing the selector on the target.

- (id) valueForRow:(DADataTableRow *)row

Parameters:

  • row: Row to calculate the value for.

visible  assign    (declared in DAFieldDefinition)

Specifies whether this field should be visible in user interfaces. This property is not used directly by the Data Abstract framework, but can be queried by user interface code to determine whether to see the field (for example in a table view or a field picker) or not. visible will be initialized based on the value set in the Schema, server-side, but can be changed within the client, if necessary.

@property (assign) BOOL visible

 

dataType    (declared in DAFieldDefinition)

Specifies the Data Type for the field.

@property (readonly) enum DADataType dataType

dataTypeName    (declared in DAFieldDefinition)

Returns the readable name of the fields data type, as defined by the dataType property.

@property (readonly) NSString *dataTypeName

name    (declared in DAFieldDefinition)

Specifies the uniqe name of the field within the data table. The field can be queried by this name using KVC's valueForKey: and setValue:forKey: methods on the individual DADataTableRows.

@property (readonly) NSString *name

position    (declared in DAFieldDefinition)

Returns the position or index of the field within the data table. This is mainly for internal use; regular field access should use the name and not rely on position.

@property (readonly) NSInteger position

properties    (declared in DAFieldDefinition)

Provides access to various properties of the field as defined in the server's Schema.

@property (readonly) NSDictionary *properties

selector

Specifies the object that implements the calculation method identified by the selector.

@property (readonly) SEL selector

table    (declared in DAFieldDefinition)

Returns a reference to the DADataTable that contains this field.

@property (readonly) DADataTable *table

target

Specifies the selector identifying the method on the target that will calculate the value for this field.

@property (readonly) id target

visible  assign    (declared in DAFieldDefinition)

Specifies whether this field should be visible in user interfaces. This property is not used directly by the Data Abstract framework, but can be queried by user interface code to determine whether to see the field (for example in a table view or a field picker) or not. visible will be initialized based on the value set in the Schema, server-side, but can be changed within the client, if necessary.

@property (assign) BOOL visible

 

initWithDataTable:name:dataType:target:selector:

Initializes a new instance of a calculated field.

- (id) initWithDataTable:(DADataTable *)ownerTable name:(NSString *)fieldName dataType:(enum DADataType)dataType target:(id)target selector:(SEL)selector

Parameters:

  • ownerTable: Specifies the DADataTable this field will be defined for.
  • fieldName: Specifies the unique name of this field within the data table.
  • dataType: Specifies the Data Type for the newly calculated field.
  • target: Specifies the object that implements the calculation method identified by the selector.
  • selector: Specifies the selector identifying the method on the target that will calculate the value for this field.

initWithTable:    (declared in DAFieldDefinition)

Initializes new DAFieldDefinition instance with given data table

- (id) initWithTable:(DADataTable *)ownerTable

Parameters:


initWithTable:name:    (declared in DAFieldDefinition)

Initializes a new DAFieldDefinition instance with given data table and field name.

- (id) initWithTable:(DADataTable *)ownerTable name:(NSString *)fieldName

Parameters:

  • ownerTable:
  • fieldName:

predicateEditorRowTemplates    (declared in DAFieldDefinition)

Returns an array with one or more NSPredicateEditorRowTemplates that match the field definition, for use in an NSPredicateEditor. Usually, you will not call 'send this message' to an individual field, but use the DADataTable's defaultPredicateEditorRowTemplates method. See also Working with NSPredicateEditor (Xcode (Mac)).

- (NSArray *) predicateEditorRowTemplates

setProperty:toValue:    (declared in DAFieldDefinition)

Updates a property stored in the properties list.

- (void) setProperty:(NSString *)propertyName toValue:(NSString *)propertyValue

Parameters:

  • propertyName: name of the property for which we want to set new value
  • propertyValue: new value we want to set.

valueForRow:

For internal use, returns the calculated value for a given row, by performing the selector on the target.

- (id) valueForRow:(DADataTableRow *)row

Parameters:

  • row: Row to calculate the value for.

Descendants

See Also