WWW.BOOK.DISLIB.INFO
FREE ELECTRONIC LIBRARY - Books, dissertations, abstract
 
<< HOME
CONTACTS



Pages:     | 1 |   ...   | 2 | 3 || 5 | 6 |   ...   | 27 |

«Introduction to Core Data Programming Guide 11 Who Should Read This Document 11 Organization of This Document 11 See Also 13 Technology Overview 14 ...»

-- [ Page 4 ] --

Entities You can specify that an entity is abstract—that is, that you will not create any instances of that entity. You typically make an entity abstract if you have a number of entities that all represent specializations of (inherit from) a common entity which should not itself be instantiated. For example, in a drawing application you might have a Graphic entity that defines attributes for x and y coordinates, color, and drawing bounds. You never, though, instantiate a Graphic. Concrete sub-entities of Graphic might be Circle, TextArea, and Line.

Properties An entity's properties are its attributes and relationships, including its fetched properties (if it has any). Amongst other features, each property has a name and a type. Attributes may also have a default value. A property name cannot be the same as any no-parameter method name of NSObject or NSManagedObject—for example, you cannot give a property the name “description” (see NSPropertyDescription).

–  –  –

Transient properties are properties that you define as part of the model, but which are not saved to the persistent store as part of an entity instance's data. Core Data does track changes you make to transient properties, so they are recorded for undo operations.

Note: If you undo a change to a transient property that uses non-modeled information, Core Data does not invoke your set accessor with the old value—it simply updates the snapshot information.

Attributes Core Data natively supports a variety of attribute types, such as string, date, and integer (represented as instances of NSString, NSDate, and NSNumber respectively). If you want to use an attribute type that is not natively supported, you can use one of the techniques described in “Non-Standard Persistent Attributes” (page 91).

You can specify that an attribute is optional—that is, it is not required to have a value. In general, however, you are discouraged from doing so—especially for numeric values (typically you can get better results using a mandatory attribute with a default value—in the model—of 0). The reason for this is that SQL has special comparison behavior for NULL that is unlike Objective-C's nil. NULL in a database is not the same as 0, and searches for 0 will not match columns with NULL.

false == (NULL == 0) false == (NULL != 0)

Moreover, NULL in a database is not equivalent to an empty string or empty data blob, either:

false == (NULL == @"") false == (NULL != @"") This has no bearing on relationships.

Relationships Core Data supports to-one and to-many relationships, and fetched properties. Fetched properties represent weak, one-way relationships. In the employees and departments domain, a fetched property of a department might be "recent hires" (employees do not have an inverse to the recent hires relationship).

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Managed Object Models Features of a Managed Object Model You can specify the optionality and cardinality of a relationship, and its delete rule. You should typically model a relationship in both directions. A many-to-many relationship is one in which a relationship and its inverse are both to-many. Relationships are described in greater detail in “Relationships and Fetched Properties” (page 82).

Fetch Request Templates You use the NSFetchRequest class to describe fetch requests to retrieve objects from a persistent store. It is often the case that you want to execute the same request on multiple occasions, or execute requests that follow a given pattern but which contain variable elements (typically supplied by the user). For example, you might want to be able to retrieve all publications written by a certain author, perhaps after a date specified by the user at runtime.

You can predefine fetch requests and store them in a managed object model as named templates. This allows you to pre-define queries that you can retrieve as necessary from the model. Typically, you define fetch request templates using the Xcode data modeling tool (see Xcode Tools for Core Data ). The template may include variablelikepredicate.eps variables, as shown in Figure 2.

Core Data Programming Guide Apple Inc., 07/2012 Figure 2 Xcode predicate builder For more about using fetch request templates, see “Accessing and Using a Managed Object Model at Runtime” (page 33).

User Info Dictionaries Many of the elements in a managed object model—entities, attributes, and relationships—have an associated user info dictionary. You can put whatever information you want into a user info dictionary, as key-value pairs.

Common information to put into the user info dictionary includes version details for an entity, and values used by the predicate for a fetched property.

Configurations A configuration has a name and an associated set of entities. The sets may overlap—that is, a given entity may appear in more than one configuration. You establish configurations programmatically using setEntities:forConfiguration: or using the Xcode data modeling tool (see Xcode Tools for Core Data ),

and retrieve the entities for a given configuration name using entitiesForConfiguration:.

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Managed Object Models Features of a Managed Object Model You typically use configurations if you want to store different entities in different stores. A persistent store coordinator can only have one managed object model, so by default each store associated with a given coordinator must contain the same entities. To work around this restriction, you can create a model that contains the union of all the entities you want to use. You then create configurations in the model for each of the subsets of entities that you want to use. You can then use this model when you create a coordinator. When you add stores, you specify the different store attributes by configuration. When you are creating your configurations, though, remember that you cannot create cross-store relationships.





–  –  –

This article describes how you use a managed object model in your application.

Creating and Loading a Managed Object Model You usually create a model in Xcode, as described in Core Data Model Editor Help. You can also create a model entirely in code, as show in Listing 3 (page 37) and described in Core Data Utility Tutorial —typically, however, this is too long-winded to consider in anything but the most trivial application. (You are nevertheless encouraged to review the tutorial to gain an understanding of what the modeling tool does, and in particular to gain an appreciation that the model is simply a collection of objects.) Compiling a Data Model A data model is a deployment resource. In addition to details of the entities and properties in the model, a model you create in Xcode contains information about the diagram—its layout, colors of elements, and so on.

This latter information is not needed at runtime. The model file is compiled using the model compiler, momc, to remove the extraneous information and make runtime loading of the resource as efficient as possible. An xcdatamodeld “source” directory is compiled into a momd deployment directory, and an xcdatamodel “source” file is compiled into a mom deployment file.

momc is located in /Developer/usr/bin/. If you want to use it in your own build scripts, its usage is momc source destination, where source is the path of the Core Data model to compile and destination is the path of the output.

Loading a Data Model In some cases, you do not have to write any code to load a model. If you use a document-based application on OS X, NSPersistentDocument manages the task of finding and loading your application’s model for you.

If you use Xcode to create a non-document application that uses Core Data (for OS X or for iOS), the application delegate includes code to retrieve the model. The name of a model—as represented by the filename used to store it on disk—is not relevant at runtime. Once the model is loaded by Core Data, the filename is meaningless and has no use, so you can name the model file whatever you like.

If you want to load a model yourself, there are two mechanisms you can use:

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using a Managed Object Model Creating and Loading a Managed Object Model

You can load a single model from a specific URL, using the instance method initWithContentsOfURL:.

● This is the generally-preferred technique. Typically an application has a single model, and using this method you ensure that you load only that model. You can also load individual models via URLs and then unify them using modelByMergingModels: before instantiating a coordinator with them.

In cases where you have more than one model—and particularly in cases where the models represent different versions of the same schema—knowing which model to load is essential (merging together models with the same entities at runtime into a single collection would cause naming collisions and errors).

This method is also useful if you want to store the model outside of the bundle for your application, and so need to reference it via a file-system URL.

You can create a merged model from a specific collection of bundles, using the class method ●

mergedModelFromBundles:.

This method may be useful in cases where segregation of models is not important—for example, you may know your application and a framework it links to both have models you need or want to load. The class method allows you to easily load all of the models at once without having to consider what the names are, or put in specialized initialization code to ensure all of your models are found.

Problems May Arise if Your Project Contains More Than One Model There are a few situations in which you may encounter problems when trying to load a model. Typically these are caused by the build products of your project being out of date combined with use of the class method

mergedModelFromBundles:.

If you simply rename your model file, Core Data attempts to merge the current and the old versions and ●

you get an error similar to the following:

reason = "'Can't merge models with two different entities named 'EntityName''";

If you create a new model that contains different entities from those in your original model, then Core ● Data merges the old and new models. If you have an existing store, you get an error similar to the following

when you attempt to open it:

reason = "The model used to open the store is incompatible with the one used to create the store";

There are two solutions:

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using a Managed Object Model Changing the Schema Makes a Model Incompatible With Old Stores Make sure that you clean any old build products before running the application. If the application bundle ● itself contains old model files, you can delete the application.

Instead of mergedModelFromBundles:, use initWithContentsOfURL: to initialize the model. The ● URL uniquely identifies a model so that Core Data will not merge the current model with any legacy models.

Changing the Schema Makes a Model Incompatible With Old Stores Because a model describes the structure of the data in a persistent store, changing any parts of a model that alters the schema renders it incompatible with (and so unable to open) the stores it previously created. If you change your schema, you therefore need to migrate the data in existing stores to new version (see Core Data Model Versioning and Data Migration Programming Guide ). For example, if you add a new entity or a new attribute to an existing entity, you will not be able to open old stores; if you add a validation constraint or set a new default value for an attribute, you will be able to open old stores.

Important: If you want to change the model but also retain the ability to open stores created using a previous version of the model, you must keep the previous version of the model (as a version in a versioned model). Core Data cannot open a store for which it has no compatible model. Thus, if you want to change

the model but also retain the ability to open existing stores, you must:



Pages:     | 1 |   ...   | 2 | 3 || 5 | 6 |   ...   | 27 |


Similar works:

«Dagmar Barth-Weingarten Weil die Hälfte eben erst die Hälfte ist – zur prosodischen Gestaltung als Projektionsmittel bei konzessiven Konstruktionen im Englischen One of the questions of conversation analysis is how speakers organise their turns in such a way that conversation continues smoothly, e.g. with regard to turn taking. It has been observed that turn endings are not only signalled by syntactic completeness of the turn construction units, but by entire bundles of features from...»

«See discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/272355255 Prediction of vegetation development with and without rewetting Chapter · January 2011 DOI: 10.13140/2.1.1985.3605 READS 3 authors, including: Annett Thiele University of Greifswald 23 PUBLICATIONS 110 CITATIONS SEE PROFILE All in-text references underlined in blue are linked to publications on ResearchGate, Available from: Annett Thiele...»

«Elektrische Antriebe mit dauermagneterregten Maschinen im dynamischen sensorlosen Betrieb An der Fakultät für Elektrotechnik der Helmut-Schmidt-Universität Universität der Bundeswehr Hamburg zur Erlangung des akademischen Grades eines Doktor-Ingenieurs eingereichte DISSERTATION von Bassel Sahhary Hamburg 2008 Erstgutachter: Prof. Dr.-Ing. Ekkehard Bolte Helmut-Schmidt-Universität/ Universität der Bundeswehr Hamburg Professur für Elektrische Maschinen und Antriebe Zweitgutachter: Prof....»

«LCA30 VT LCA30 RVT LCA30 VA BEDIENUNGSANLEITUNG OPERATING INSTRUCTION -1Einführung Alle in diese Anleitung beschriebenen Flügelradanemometer der Reihe LCA verfügen über eine Digitalanzeige der Strömungsgeschwindigkeit in m/s als auch in Imperial Einheiten. (zusätzliche Anzeige des Volumenstromes bei LCA30VA). Konstruiert für einfache Handhabung verfügt die LCA-Reihe über einen Kontrollschalter seitlich am Griff. Um das Gerät ein bzw., auszuschalten ist eine Schiebeschalter unterhalb...»

«T H E C IT Y O F NE W Y O R K OFFICE O F T H E P R E S I D E N T BOROUGH OF MANHATTAN GALE A. BREWER BOROUGH PRESIDENT March 12, 2014 Recommendation on ULURP Application Nos. C 140181 ZMM, N 140182 ZRM, C 140183 ZSM, N 140184 ZCM, and C 140185 HAM – Site 7 By the New York City Department of Housing Preservation and Development PROPOSED ACTIONS The New York City Department of Housing Preservation and Development (“HPD”) and a development team of the Clinton Housing Development Company...»

«Allgemeines Treatment und Vertrag EAGLE PICTURES GERMANY WEDDING ENTERTAINMENT Ihr Ansprechpartner/ ausführender Produzent: Sebastian Bauer Fon: +49 (0) 173 714 26 57 Mail: sebastianbauer@eaglepictures.de EAGLE PICTURES GERMANY Am Sonnengarten 4 88069 Tettnang www.eaglepictures.de Stand Januar 2015 BEISPIEL EINER HOCHZEITSFILMPRODUKTION (WORKFLOW) Vorbesprechung Unverbindliche Reservierung des Termins Vorführung von Demos Besprechung Konzeption Konkretes Angebot Vertragsabschluss Allgemeine...»

«LUDWIG VAN BEETHOVEN (1770–1827) Piano Sonata no.4 in E flat op.7 Klaviersonate Nr. 4 Es-dur · Sonate pour piano no4 en mi bémol majeur 1 I Allegro molto e con brio 7.45 2 II Largo, con gran espressione 8.10 3 III Allegro 5.07 4 IV Rondo: Poco allegretto e grazioso 6.50 Piano Sonata no.14 in C sharp minor op.27 no.2 ‘Moonlight’ Klaviersonate Nr. 14 cis-moll „Mondscheinsonate“ Sonate pour piano no14 en do dièse mineur « Clair de lune » 5 I Adagio sostenuto 5.10 6 II Allegretto...»

«Baldwin-Wallace College Bach Festival Celebrating 77 years of exceptional music The Oldest Collegiate Bach Festival in the Nation Annotated Program April 17–19, 2009 OUR SPONSORS The Adrianne and Robert Andrews Bach Festival Fund in honor of Amelia & Elias Fadil neighborhoods and are vital to our children’s success. To learn more, visit www.cacgrants.org. On the cover: The Kulas Musical Arts Building in the 1940s. Seventy-Seventh AnnuAl Bach Festival the Oldest cOllegiate Bach Festival in...»

«ADVANCED DUNGEONS & DRAGONS® 2nd Edition Player's Handbook Rules Supplement The Complete Book of Elves CREDITS Written by Colin McComb Edited by Dori Hein Overseen and Advice Given by Steve Winter Color Illustrations by Brom, Larry Elmore, and John & Laura Lakey Black and White Art by Terry Dykstra Decorative Art by Robin Raab Typeset by Gaye O'Keefe Invaluable assistance or sustenance (in one form or another) given by L. Richard Baker III, Wolfgang Baur, Tim Beach, Wendy Bienvenu, Elaine...»

«« Ausgabe 65 « Juli 2014 « © 2014 TWT-Team « tw.wusel.info « Neues aus dem Dev Blog Wie die Bären lernten, sich zu drehen Die Multiplayer-Inhalte sollen das „nächste große Ding“ in unserem Spiel werden und daher ist es erfreulich zu wissen, dass weiter intensiv daran gearbeitet wird. Bedingt durch die Tatsache, dass wir eine monatlich erscheinende Zeitung sind, ist unsere Information nicht mehr ganz frisch. Wir wollen euch aber trotzdem nicht den aktuellsten Eintrag der Entwickler...»





 
<<  HOME   |    CONTACTS
2016 www.book.dislib.info - Free e-library - Books, dissertations, abstract

Materials of this site are available for review, all rights belong to their respective owners.
If you do not agree with the fact that your material is placed on this site, please, email us, we will within 1-2 business days delete him.