reffec.com

Displaying the Products for Sale and Updating the Stock in Software Encoder USS Code 39 in Software Displaying the Products for Sale and Updating the Stock

Displaying the Products for Sale and Updating the Stock use software barcode 3 of 9 implement todraw code 39 full ascii on software Radio-frequency identification Versioning The concept of mi grations and versioning is related to the problems that are caused when we make some changes in our data model. Like if we add or delete some attribute(s) from an existing Entity or add one more Entity to our data model. In that case, our new version of application will crash when launched because of the simple fact that the existing data in the persistent store on the iPhone will be unusable in the new version of our application.

This problem can be corrected at our end by selecting Reset Content and Settings option from the iPhone simulator menu or by uninstalling the application from the iPhone and re-installing it. Consequently, the CoreData will create a new persistent store on the basis of the new Data model when the application is launched. But the problem occurs at the client"s end, who has the older application, and a new version of the application is sent to them.

They cannot uninstall and re-install the application as they will lose their existing data. To solve such problems, Xcode has a built-in version-control mechanism that helps in applying a new version to our revised data model. In this versioning facility, the older data model will be kept (and not erased) and the revised data model is assigned a new version number.

This will not only save the user from losing the existing data but will also help in upgrading the older data into the newer version.. Creating a new Data Model version Let"s assume we h ave an application with the name demopredicate that has a data model: demopredicate.xcdatamodel. To create a new Data Model version, single click demopredicate.

xcdatamodel in Xcode Project window and select Design . Data Model Add Model Versio n option. It will add a new version of our data model. We will find that our demopredicate.

xcdatamodel file gets disappeared from the Resources group and is replaced by a new resource with the demopredicate.xcdatamodeld with a disclosure triangle next to it, as shown in the following screenshot:. [ 300 ]. 11 . On selecting the Software Code 3/9 disclosure triangle of demopredicate.xcdatamodeld, all the versions of our data model will be displayed and the current data model that is being used by our application will be represented by an icon with green checkmark on it. When we create a new version of our data model, the latest version is represented by the file with the original name, and the older version is represented by a copy that is created with the same name with an incrementally larger number affixed to the end.

Like in the preceding screenshot, the file: demopredicate2.xcdatamodel is the original data model. As we have the older version of our data model safe, we can now make changes to the current version (latest version) as desired.

We can always switch to the older data model to see our old existing data. To switch to any data model, that is, to make any data model the current version (to work on), select the data model file from the Xcode Project window and select the Design . Data Model Set Current Version option. [ 301 ]. Displaying the Products for Sale and Updating the Stock Migrations An exception is t Code 3/9 for None hrown if Core Data finds that the persistent store is incompatible with the current data model. To solve this problem, we use a concept called Migration, which tells Core Data to move data from the old persistent store to a new one that matches the current data model. Migrations are of two types: Lightweight and Standard.

Lightweight migration is easy to achieve (requires no coding) and is used when small modifications are applied to our data model that includes adding or removing attributes from an entity, adding or deleting an existing entity from the data mode, and so on. Whereas Standard migration is a bit complicated to implement as it requires creation of a mapping model and coding to inform Core Data to move the data from the old persistent store to the new one. The standard migration is out of scope of this book.

We will only discuss lightweight migration in this book.. To implement ligh tweight migration to our application, we have to do some modifications in our application delegate file. So, open the probAppDelegate.m file (refer to the 4, Designing the Data Model and Building Data Objects for Customers) and locate the persistentStoreCoordinator method, which will have the code as shown next:.

- (NSPersistentSt Software 39 barcode oreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"customersdata.sqlite"]]; NSError *error; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLite StoreType configuration:nil URL:storeUrl options:nil error:&error]) { // Handle error } return persistentStoreCoordinator; }.
Copyright © reffec.com . All rights reserved.