Building the data object for the MasterProduct entity

To build the data 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 option. 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 left-pane 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:

// MasterProduct.h
// prob
#import <CoreData/CoreData.h>
@interface MasterProduct : NSManagedObject
{
}
@property (nonatomic, retain) NSNumber * price;
@property (nonatomic, retain) NSNumber * quantity;
@property (nonatomic, retain) id image;
@property (nonatomic, retain) NSString * itemname;
@end

In the preceding 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:

// MasterProduct.m
// prob
#import "MasterProduct.h"
@implementation MasterProduct
@dynamic price;
@dynamic quantity;
@dynamic image;
@dynamic itemname;
@end

In the implementation file, we find that the properties are marked as dynamic to inform the compiler not to generate accessors and mutators for the properties and will be generated by the super class at runtime and hence not to display any warning message related to them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.114.154