Difference Between Temporary and Derived Properties of a Master Data Object

What is the difference between temporary and derived properties of the master data object? I would like to create a "virtual" property that can be used in a select operation to return the localized country names from the main data object.

The operation should be done as follows:

  • get country name from english database
  • execute NSLocalizedString (countryNameInEnglish, nil) to get the localized country name.

2 must be fulfilled by this "virtual" property.

Which one should I use? transient or derivative and how to do it?

I have nothing to show you because I have no idea what I should be using.

thank

+3


source to share


1 answer


According to Apple's guidance for Custom Constant Attributes :

You can use non-standard types for persistent attributes either by using transient attributes or by using the transient property to represent a custom attribute supported by a supported persistent property. The principle behind the two approaches is the same: you expose to the consumers of your object an attribute of the type you want, and behind the scenes you convert to a type that Core Data can manipulate. The difference between the approaches is that with transformable attributes, you only specify one attribute, and the transform is handled automatically. In contrast, with transient properties, you specify two attributes and you need to write code to perform the transformation.

I suggest using transient attributes. The idea is that you create 2 string attributes: countryName (non-transient) and localizedCountryName (transient):



How to set "transient" flag

And then, in your NSManagedObjectSubclass, you simply implement a getter for localizedCountryName:

- (NSString *)localizedCountryName
{
    NSString *result;

    if ([self.countryName length] > 0) {
        result = NSLocalizedString(self.countryName, nil);
    }

    return result;
}

      

+8


source







All Articles