FREE ELECTRONIC LIBRARY - Books, dissertations, abstract

Pages:     | 1 |   ...   | 16 | 17 || 19 | 20 |   ...   | 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 18 ] --

1. Given an instance of a persistent store, you can set its metadata using the

NSPersistentStoreCoordinator instance method, setMetadata:forPersistentStore:.

2. You can set the metadata without the overhead of creating a persistence stack using the NSPersistentStoreCoordinator class method,


There is again an important difference between these approaches. If you use setMetadata:forPersistentStore:, you must save the store (through a managed object context) before the new metadata is saved. If you use setMetadata:forPersistentStoreOfType:URL:error:, however, the metadata is updated immediately (and the last-modified date of the file changed). This difference has particular implications if you use NSPersistentDocument on OS X. If you update the metadata using setMetadata:forPersistentStoreOfType:URL:error: while you are actively working on the persistent store (that is, while there are unsaved changes), then when you save the document you will see a warning, “This document's file has been changed by another application since you opened or saved it.” To avoid this, you should instead use setMetadata:forPersistentStore:. To find the document’s persistent store, you typically ask the persistent store coordinator for its persistent stores (persistentStores) and use the first item in the returned array.

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

Using Persistent Stores Associate Metadata With a Store to Provide Additional Information and Support Spotlight Indexing Because Core Data manages the values for NSStoreType and NSStoreUUID, you should make a mutable copy of any existing metadata before setting your own keys and values, as illustrated in the following code fragment.

NSError *error;

NSURL *storeURL = #URL identifying the location of the store#;

NSDictionary *metadata = [NSPersistentStoreCoordinator metadataForPersistentStoreWithURL:storeURL error:&error] if (metadata == nil) {

–  –  –

NSMutableDictionary *newMetadata = [metadata mutableCopy];

newMetadata[(NSString *)kMDItemKeywords] = @[ @"MyKeyWord"] ];

// Set additional key-value pairs as appropriate.

[NSPersistentStore setMetadata:newMetadata

–  –  –

Changes made to objects’ property values should be propagated to the user interface, and user interface elements displaying the same property should be kept synchronized. Cocoa bindings provides a control layer for Cocoa but, whereas the Core Data framework focuses on the model, Cocoa bindings focus on the user interface. In many situations, Cocoa bindings makes it easy to keep the user interface properly synchronized.

The Core Data framework is designed to interoperate seamlessly with, and enhance the utility of, Cocoa bindings.

iOS: Note that Cocoa bindings are not available on iOS.

Cocoa bindings and Core Data are largely orthogonal. In general, Cocoa bindings work in exactly the same way with managed objects as with other Cocoa model objects. You can also use the same predicate objects and sort descriptors as you use to fetch objects from the persistent store to filter and sort objects in memory—for example to present in a table view. This gives you a consistent API set to use throughout your application.

There, however, are a few (typically self-evident) differences in configuration and operation.

In addition to the issues described in this article, there are a few other areas where the interaction between Core Data and Cocoa Bindings may cause problems; these are described in “Troubleshooting Core Data” (page 149), in particular:

“Custom relationship set mutator methods are not invoked by an array controller” (page 157) ● “Cannot access contents of an object controller after a nib is loaded” (page 157) ● “Table view or outline view contents not kept up-to-date when bound to an NSArrayController or ● NSTreeController object” (page 159) Modulo these exceptions, everything that is discussed and described in Cocoa Bindings Programming Topics applies equally to Core Data-based applications and you should use the same techniques for configuring and debugging bindings when using Core Data as you would if you were not using Core Data.

Additions to Controllers The main area where Core Data adds to Cocoa bindings is in the configuration of the controller objects such

as NSObjectController and NSArrayController. Core Data adds the following features to those classes:

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

Core Data and Cocoa Bindings Automatically Prepares Content Flag A reference to a managed object context that is used for all fetches, insertions, and deletions.

● If a controller's content is a managed object or collection of managed objects, you must either bind or set the managed object context for the controller.

An entity name that is used instead of the content object class to create new objects ● A reference to a fetch predicate that constrains what is fetched to set the content if the content is not set ● directly A content binding option ("Deletes Objects On Remove") that—if the content is bound to a ● relationship—specifies whether objects removed from the controller are deleted in addition to being removed from the relationship Automatically Prepares Content Flag If the "automatically prepares content" flag (see, for example, setAutomaticallyPreparesContent:) is set for a controller, the controller's initial content is fetched from its managed object context using the controller's current fetch predicate. It is important to note that the controller's fetch is executed as a delayed operation performed after its managed object context is set (by nib loading)—this therefore happens after awakeFromNib and windowControllerDidLoadNib:. This can create a problem if you want to perform an operation with the contents of an object controller in either of these methods, since the controller's content is nil. You can work around this by executing the fetch "manually" with fetchWithRequest:merge:error:. You pass nil as the fetch request argument to use the default request, as illustrated in the following code fragment.

- (void)windowControllerDidLoadNib:(NSWindowController *) windowController { [super windowControllerDidLoadNib:windowController];

–  –  –

BOOL ok = [arrayController fetchWithRequest:nil merge:NO error:&error];


Entity Inheritance If you specify a super entity as the entity for a fetch request, the fetch returns matching instances of the entity and sub-entities (see “Fetching and Entity Inheritance” (page 66)). As a corollary, if you specify a super entity as the entity for a controller, it fetches matching instances of the entity and any sub-entities. If you specify an abstract super-entity, the controller fetches matching instances of concrete sub-entities.

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

Core Data and Cocoa Bindings Filter Predicate for a To-many Relationship Filter Predicate for a To-many Relationship Sometimes you may want to set up a filter predicate for a search field that lets a user filter the contents of an array controller based on the destination of a to-many relationship. If you want to search a to-many relationship, you need to use an ANY or ALL in the predicate. For instance, if you want to fetch Departments in which at least one of the employees has the first name "Matthew", you use an ANY operator as shown in the following


NSPredicate *predicate = [NSPredicate predicateWithFormat:

@"ANY employees.firstName like 'Matthew'"];

You use the same syntax in a search field's predicate binding:

ANY employees.firstName like $value Note: You cannot use the contains operator (for example, ANY employees.firstName contains 'Matthew') because the contains operator does not work with the ANY operator.

–  –  –

NSPredicate *predicate = [NSPredicate predicateWithFormat:

@"ANY employees.firstName like 'Matt*'"];

You cannot, though, use the same syntax within a search field's predicate binding:

// does not work ANY employees.firstName like '$value*' The reasons for this are described in Predicate Programming Guide —putting quotes in the predicate format prevents the variable substitution from happening. Instead, you must use substitute any wildcards first as

illustrated in this example:

NSString *value = @"Matt";

NSString *wildcardedString = [NSString stringWithFormat:@"%@*", value];

–  –  –

[[NSPredicate predicateWithFormat:@"ANY employees.firstName like %@", wildcardedString];

By implication, therefore, you must write some code to support this behavior.

Note: You may find that search field predicate bindings filter results inconsistently with wildcard characters. This is due to a bug in NSArrayController. The workaround is to create a subclass of NSArrayController and override arrangeObjects: to simply invoke super‘s implementation.

–  –  –

If your application contains more than one managed object context and you allow objects to be modified in more than context, then you need to be able to reconcile the changes.

Disjoint Edits The object graph associated with any given managed object context must be internally consistent. If you have multiple managed object contexts in the same application, however, it is possible that each may contain objects that represent the same records in the persistent store, but whose characteristics are mutually inconsistent. In

–  –  –

an employee application, for example, you might have two separate windows that display the same set of employees, but distributed between different departments and with different managers, as shown in Figure 1.

Figure 1 Managed object contexts with mutually inconsistent data values Ultimately though there can only be one “truth” and differences between these views must be detected and reconciled when data is saved. When one of the managed object contexts is saved, its changes are pushed through the persistent store coordinator to the persistent store. When the second managed object context is saved, conflicts are detected using a mechanism called optimistic locking; how the conflicts are resolved depends on how you have configured the context.

Conflict Detection and Optimistic Locking When Core Data fetches an object from a persistent store, it takes a snapshot of its state. A snapshot is a dictionary of an object’s persistent properties—typically all its attributes and the global IDs of any objects to which it has a to-one relationship. Snapshots participate in optimistic locking. When the framework saves, it compares the values in each edited object’s snapshot with the then-current corresponding values in the persistent store.

–  –  –

If the values are the same, then the store has not been changed since the object was fetched, so the save ● proceeds normally. As part of the save operation, the snapshots' values are updated to match the saved data.

If the values differ, then the store has been changed since the object was fetched or last saved; this ● represents an optimistic locking failure.

Conflict Resolution You can get an optimistic locking failure if more than one persistence stack references the same external data store (whether you have multiple persistence stacks in a single application or you have multiple applications).

In this situation there is the possibility that the same conceptual managed object will be edited in two persistence stacks simultaneously. In many cases, you want to ensure that subsequent changes made by the second stack do not overwrite changes made by the first, but there are other behaviors that may be appropriate. You can choose the behavior by choosing for the managed object context a merge policy that is suitable for your situation.

Pages:     | 1 |   ...   | 16 | 17 || 19 | 20 |   ...   | 27 |

Similar works:

«© Entomofauna Ansfelden/Austria; download unter www.biologiezentrum.at Entomofauna ZEITSCHRIFT FÜR ENTOMOLOGIE Band 27, Heft 22: 277-284 ISSN 0250-4413 Ansfelden, 30. April 2006 The present situation of the Mutillidae-fauna of Turkey (Hymenoptera, Aculeata) Erol YILDIRIM Abstract The study is based upon material of the family Mutillidae, collected in 1992 to 2005 in different localities of Turkey, and upon related studies on Mutillidae of Turkey which were reviewed. Including the taxa new for...»

«Learning and Teaching in Higher Education, Issue 1, 2004-05 Assessment for Learning SALLY BROWN Independent Higher Education Consultant; Visiting Professor at the Robert Gordon University (Aberdeen) and at Buckinghamshire Chilterns University College, UK The changing nature of assessment Assessment is probably the most important thing we can do to help our students learn. We may not like it, but students can and do ignore our teaching; however, if they want to get a qualification, they have to...»

«018530 SWITCH Sustainable Water Management in the City of the Future Integrated Project Global Change and Ecosystems DELIVERABLE 2.3.2a: A GIS DATA INTEGRATION TOOL FOR ASSESSING STORMWATER MANAGEMENT OPTIONS: USER GUIDE Due date of deliverable: January 2009 Actual submission date: June 2009 Start date of project: 1 February 2006 Duration: 60 months Organisation name of lead contractor for this deliverable: Middlesex University Prepared by Christophe Viavattene, Middlesex University Revision:...»


«Az.: L 9 SO 17/11 Az.: S 17 SO 269/07 SG Schleswig SCHLESWIG-HOLSTEINISCHES LANDESSOZIALGERICHT verkündet am 27. Febr. 2013 -Justizangestellte als Urkundsbeamtin der Geschäftsstelle IM NAMEN DES VOLKES URTEIL In dem Rechtsstreit Klägerin und Berufungsbeklagte Prozessbevollmächtigte: Rechtsanwältin gegen Stadt Neumünster Der Oberbürgermeister Fachbereich Rechtsabteilung, Großflecken 59, 24534 Neumünster, Beklagte und Berufungsklägerin beigeladen: AOK NordWest Die Gesundheitskasse -,...»

«SAS Global Forum 2008 Beyond the Basics Paper 043-2008 ETL and Data Quality: Which Comes First? Emilio Power, ThotWave Technolgies, LLC, Chapel Hill, NC Greg Nelson, ThotWave Technolgies, LLC, Chapel Hill, NC ABSTRACT Usually, an early task in any data warehousing project is a detailed examination of the source systems, including an audit of data quality. Data quality issues could include inconsistent data representation, missing data and difficulty around understanding relationships between...»

«Modulhandbuch 17 831 Molekulare Biotechnologie Wissenschaftszentrum Weihenstephan für Ernährung, Landnutzung und Umwelt Technische Universität München http://www.tum.de/ www.wzw.tum.de Modulhandbuch Generiert am 25.08.2013 Verzeichnis Modulbeschreibungen CH0935: Anorganische Chemie (Anorganische Chemie) CH0936: Biochemie 1 (Biochemie 1) WZ2002: Einführung in die Genetik (Einführung in die Genetik) CH0937: Mathematik (Mathematik) PH9913: Experimentalphysik inkl. Praktikum...»

«Interview Hans-Joachim Koloss, 19.01.2009 Herr Koloss, in welchem sozialen Umfeld sind Sie aufgewachsen? Meine Familie stammt aus Ostpreußen, wo mein Vater bis 1945 auf mehreren Gütern als Oberinspektor bzw. Administrator diente, zuletzt auf einem Gut im Kreis Neidenburg an der polnischen Grenze. Ich selbst wurde 1938 in Königsberg geboren. Nach unserer Flucht kamen wir im März 1945 nach Ganderkesee im Landkreis Oldenburg. Als britische Truppen den Ort am 21. April 1945 einnahmen, wurde das...»

«Wissenschaftlich-technische Zusammenarbeit mit Brasilien BMBF-Verbundprojekt Nachhaltiges Umweltmanagement in brasilianischen Häfen Fallstudie Paranaguá FKZ 03F0452A-C, 03F0452E-F, 03F0454A 01.11.2006 31.10.2009/31.12.2009 ABSCHLUSSBERICHT Projektkoordination: Prof. Dr. R. Mayerle Forschungsund Technologiezentrum Westküste Christian-Albrechts-Universität Kiel Hafentörn 1 D-25761 Büsum Kiel / Büsum, April 2010 Autoren des Schlussberichtes Mayerle, Roberto; Hesse, Karl-Jürgen; Ladwig,...»

«© Naturwiss.-med. Ver. Innsbruck; download unter www.biologiezentrum.at Ber. nat.-med. Verein Innsbruck Band 75 S. 91 107 Innsbruck, Okt. 1988 Die Verteilung der Ephippien von Bosmina longirostris und Ceriodaphnia pulcinella im Sediment des Piburger Sees ¿ (Ötztal, Tirol) (Cladocera, Crustácea)1* von Christian MORITZ *) (Abteilung für Limnologie am Institut für Zoologie der Universität Innsbruck) The distribution of the ephippia of Bosmina longirostris and Ceriodaphnia pulchella in the...»

<<  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.