Transformable data type in Software Make barcode code39 in Software Transformable data type

Transformable data type using barcode creator for software control to generate, create bar code 39 image in software applications. MSI Plessey The Transformab Software 39 barcode le data type is a special data type that allows us to create attributes based on an Objective-C class (custom objects). This data type is heavily used for storing instances of UIImage, UIColor, and so on. As the information stored in the persistent store has to be in the form of NSData instance, while using Transformable data type, we need to create Value Transformers to convert the custom object (information in attribute of Transformable data type) into an instance of NSData (before storing in the persistent store) and to convert the instance of NSData back to custom object while retrieving from the persistent store.

. [ 221 ]. Entering, Displaying, and Deleting the Stock In this field, we specify the name of the Value Transformer class that will be used for converting a custom object (information store in the attribute of the Transformable data type) into an NSData instance for saving in the persistent store, and vice versa. Let us name our value transformer class as: UIImageToNSDataTransformer as shown in the preceding screenshot. Let us create our value transformer class for our Transformable (image attribute) data type.

. The Value Transformer Name: field Creating a value transformer The value trans USS Code 39 for None formers are used for converting objects of image type, color type, and so on into NSData object for storing in the persistent store, and vice versa, that is, take the NSData object from the persistent store and convert it into their custom object type (older format color, image, and so on). To create the Value transformer, perform the following steps: 1. Right-click on the Classes folder in the Xcode Project window and select Add .

New File optio n. 2. Select the Objective-C class option (for the template of our new file) as shown in the following screenshot.

3. Leave the subclass of the drop-down to be NSObject. Select the Next button.

4. We will be asked to specify the name of the new NSObject subclass. Assign the name as: UIImageToNSDataTransformer.

h and select the Finish button.. [ 222 ]. 9 . The header and Software Code 39 Extended implementation files of our value transformer class: UIImageToNSDataTransformer will be created. Write the following code in the file UIImageToNSDataTransformer.h:.

// // UIImageToNSDataTransformer.h prob #import <UIKit/UIKit.h> @interface UIImageToNSDataTransformer : NSValueTransformer { } @end As we can see i n the preceding code, for creating a value transformer, we need to subclass the NSValueTransformer class. Write the following code in the UIImagetoNSDataTransformer.m file:.

// // UIImageToNSDataTransformer.m prob #import "UIImag eToNSDataTransformer.h" @implementation UIImageToNSDataTransformer +(Class)transformedValueClass{ return [NSData class]; } +(BOOL) allowsReverseTransformation{ return YES; } -(id)transformedValue:(id) value { return UIImagePNGRepresentation(value); } -(id)reverseTransformedValue:(id) value{ return [[[UIImage alloc] initWithData:value] autorelease]; } @end. [ 223 ]. Entering, Displaying, and Deleting the Stock As we can see i 3 of 9 for None n the preceding code, we need to override the transformedValueClass method that returns the class of the converted object. This method will return an instance of the NSData class as the image will be stored in this format only in the persistent store. Recall that we want our Value Transformer to transform an instance of UIImage (data in an image attribute) to an instance of the NSData class (for storing in the persistent store) and vice versa, for retrieving the data in the form of an instance of NSData (from the persistent store) and transforming it back to the instance of the UIImage class.

The allowsReverseTransformation method is overridden for allowing reverse transformation procedure (converting the instance of NSData to the instance of UIImage). We set this method to return YES to make the reverse transformation possible. The transformedValue method is overridden to accept the instance of the UIImage class and return the instance of the transformed class (the NSData class).

Similarly, the reverseTransformedValue method is overridden to accept the instance of the transformed class (the NSData class) and transform back to the instance of the original class (the UIImage class).. Building the data object for the MasterProduct entity To build the da barcode 39 for None ta objects (classes) for the MasterProduct entity defined in the data model, follow the given steps: 1. Click any entity in the data model editor and then choose the File . New File optio n. We get a dialog box to choose the template for the new file. 2.

Select Cocoa Touch Classes from under the iPhone OS heading in the leftpane and select the Managed Object Class template. We get a dialog box that prompts for the location of generating the managed object class. Keeping the values as default select the Next button.

3. Check the MasterProduct entity in the dialog box that appears (there is no need for selecting the checkbox for Customer and Product"s entity as their managed object classes are already created). We find two checkboxes that are already checked: Generate accessors and Generate Obj-C 2.

0 Properties. Keeping the two checkboxes checked, select the Finish button. We find two files: MasterProduct.

h and MasterProduct.m (Customer.h, Customer.

m, Product.h, and Product.m were already there) generated in the Classes folder of the Xcode Project window with the following contents:.

// // MasterPro Software 39 barcode duct.h prob [ 224 ]. 9 #import < CoreData/CoreData.h> @interface MasterProduct : { } @property @property @property @property @end (nonatomic, (nonatomic, (nonatomic, (nonatomic, NSManagedObject. retain) retain) Code 3 of 9 for None retain) retain). NSNumber * pric e; NSNumber * quantity; id image; NSString * itemname;. In the precedin Software Code 39 Extended g code, we see that the properties are defined with the names: price, quantity, image, and itemname. These properties are not declared in the header file as they will be created dynamically. The implementation file, MasterProduct.

m will have the following code by default:.
Copyright © . All rights reserved.