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



Pages:     | 1 |   ...   | 24 | 25 || 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 26 ] --

How do I use my existing SQLite database with Core Data?

You don’t. Although Core Data supports SQLite as one of its persistent store types, the database format is private. You cannot create a SQLite database using native SQLite API and use it directly with Core Data (nor should you manipulate an existing Core Data SQLite store using native SQLite API). If you have an existing SQLite database, you need to import it into a Core Data store (see “Efficiently Importing Data” (page 160)).

I have a to-many relationship from Entity A to Entity B. How do I fetch the instances of Entity B related to a given instance of Entity A?

You don’t. More specifically, there is no need to explicitly fetch the destination instances, you simply invoke the appropriate key-value coding or accessor method on the instance of Entity A. If the relationship is called “widgets” then if you have implemented a custom class with a similarly named accessor method, you simply,

write:

NSSet *asWidgets = [instanceA widgets];

Otherwise you use key-value coding:

–  –  –

NSMutableSet *asWidgets = [instanceA mutableSetValueForKey:@"widgets"];

How do I fetch objects in the same order I created them?

Objects in a persistent store are unordered. Typically you should impose order at the controller or view layer, based on an attribute such as creation date. If there is order inherent in your data, you need to explicitly model that.

How do I copy a managed object from one context to another?

First, note that in a strict sense you are not copying the object. You are conceptually creating an additional reference to the same underlying data in the persistent store.

To copy a managed object from one context to another, you can use the object’s object ID, as illustrated in the following example.

NSManagedObjectID *objectID = [managedObject objectID];

NSManagedObject *copy = [context2 objectWithID:objectID];

I have a key whose value is dependent on values of attributes in a related entity—how do I ensure it is kept up to date as the attribute values are changes and as the relationship is manipulated?

There are many situations in which the value of one property depends on that of one or more other attributes in another entity. If the value of one attribute changes, then the value of the derived property should also be flagged for change. How you ensure that key-value observing notifications are posted for these dependent properties depends on which version of OS X you’re using and the cardinality of the relationship.

OS X v10.5 and later for a to-one relationship If there is a to-one relationship to the related entity, then to trigger notifications automatically you should either override keyPathsForValuesAffectingValueForKey: or implement a suitable method that follows the pattern it defines for registering dependent keys.

For example, you could override keyPathsForValuesAffectingValueForKey: as shown in the following

example:

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

Core Data FAQ I have a key whose value is dependent on values of attributes in a related entity—how do I ensure it is kept up to date as the attribute values are changes and as the relationship is manipulated?

+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key { NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];

if ([key isEqualToString:@"fullNameAndDepartment"]) { NSSet *affectingKeys = [NSSet setWithObjects:@"lastName", @"firstName",

–  –  –

} Or, to achieve the same result, you could just implement

keyPathsForValuesAffectingFullNameAndDepartment as illustrated in the following example:

+ (NSSet *)keyPathsForValuesAffectingFullNameAndDepartment { return [NSSet setWithObjects:@"lastName", @"firstName",

–  –  –

} To-many relationships keyPathsForValuesAffectingValueForKey: does not allow key-paths that include a to-many relationship.

For example, suppose you have an Department entity with a to-many relationship (employees) to a Employee, and Employee has a salary attribute. You might want the Department entity have a totalSalary attribute that is dependent upon the salaries of all the Employees in the relationship. You can not do this with, for example, keyPathsForValuesAffectingTotalSalary and returning employees.salary as a key.

There are two possible solutions in both situations:

1. You can use key-value observing to register the parent (in this example, Department) as an observer of the relevant attribute of all the children (Employees in this example). You must add and remove the parent as an observer as child objects are added to and removed from the relationship (see “Registering for Key-Value Observing”). In the observeValueForKeyPath:ofObject:change:context: method you

update the dependent value in response to changes, as illustrated in the following code fragment:

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

Core Data FAQ I have a key whose value is dependent on values of attributes in a related entity—how do I ensure it is kept up to date as the attribute values are changes and as the relationship is manipulated?





- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

–  –  –

}

- (void)updateTotalSalary { [self setTotalSalary:[self valueForKeyPath:@"employees.@sum.salary"]];

}

- (void)setTotalSalary:(NSNumber *)newTotalSalary } }

2. You can register the parent with the application's notification center as an observer of its managed object context. The parent should respond to relevant change notifications posted by the children in a manner similar to that for key-value observing.

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

Core Data FAQ In Xcode’s predicate builder, why don’t I see any properties for a fetched property predicate?

In Xcode’s predicate builder, why don’t I see any properties for a fetched property predicate?

If you want to create a predicate for a fetched property in the predicate builder in Xcode, but don’t see any properties, you have probably not set the destination entity for the fetched property.

How efficient is Core Data?

Throughout the development of Core Data, the engineering team compared the runtime performance of a generic Core Data application with that of a similar application developed without using Core Data. In general, the Core Data implementation performed better. There may nevertheless be opportunities for further optimization, and the team continues to pursue performance aggressively. For a discussion of how you can ensure you use Core Data as efficiently as possible, see “Core Data Performance” (page 140).

Core Data looks similar to EOF. What are the differences?

Core Data and EOF (the Enterprise Objects Framework that ships with WebObjects) share a common heritage, but have different goals. EOF is a Java-based framework that connects as a client to a database server. Core Data is an Objective-C-based framework designed to support desktop application development. Core Data supports a number of features not supported by EOF, and vice-versa.

Features Supported Only by EOF EOF allows you to use custom SQL, shared editing contexts, and nested editing contexts. Core Data does not provide the equivalent of an EOModelGroup—the NSManagedObjectModel class provides methods for merging models from existing models, and for retrieving merged models from bundles.

EOF supports pre-fetching and batch faulting of relationships, in OS X v10.4 Core Data does not. In OS X v10.5, when you create a fetch request, you can use setRelationshipKeyPathsForPrefetching: to specify key paths for relationships that should be fetched with the target entity.

Features Supported Only by Core Data Core Data supports fetched properties; multiple configurations within a managed object model; local stores;

store aggregation (the data for a given entity may be spread across multiple stores); customization and localization of property names and validation warnings; and the use of predicates for property validation.

–  –  –

Class Mapping There are parallels between many of the classes in Core Data and EOF.

NSManagedObject corresponds to EOGenericRecord.

● NSManagedObjectContext corresponds to EOEditingContext.

● NSManagedObjectModel corresponds to EOModel.

● NSPersistentStoreCoordinator corresponds to EOObjectStoreCoordinator.

● NSEntityDescription, NSPropertyDescription, NSRelationshipDescription, and ● NSAttributeDescription correspond to EOEntity, EOProperty, EORelationship, and EOAttribute respectively.

Change Management There is an important behavioral difference between EOF and Core Data with respect to change propagation.

In Core Data, peer managed object contexts are not "kept in sync" in the same way as editing contexts in EOF.

Given two managed object contexts connected to the same persistent store coordinator, and with the "same" managed object in both contexts, if you modify one of the managed objects then save, the other is not re-faulted (changes are not propagated from one context to another). If you modify then save the other managed object, then (at least if you use the default merge policy) you will get an optimistic locking failure.

Multi-Threading The policy for locking a Core Data managed object context in a multithreaded environment is not the same policy as for an editing context in EOF.

OS X Desktop These questions are only relevant to OS X/desktop.

How do I get the GUI to validate the data entered by the user?

Core Data validates all managed objects when a managed object context is sent a save: message. In a Core Data document-based application, this is when the user saves the document. You can have the GUI validate it as the data is being entered by selecting the “Validates Immediately” option for a value binding in the Interface Builder bindings inspector. If you establish the binding programmatically, you supply in the binding options dictionary a value of YES (as an NSNumber object) for the key NSValidatesImmediatelyBindingOption (see “Binding Options”).

–  –  –

For details of how to write custom validation methods, see the subclassing notes for NSManagedObject.

When I remove objects from a detail table view managed by an array controller, why are they not removed from the object graph?

If an array controller manages the collection of objects at the destination of a relationship, then by default the remove method simply removes the current selection from the relationship. If you want removed objects to be deleted from the object graph, then you need to enable the “Deletes Objects On Remove” option for the contentSet binding.

How do I get undo/redo for free in my non-document-architecture-based app?

In a Core Data document-based application, the standard NSDocument undo manager is replaced by the document’s managed object context’s undo manager. In a non-document-based application for desktop OS X, your window’s delegate can supply the managed object context’s undo manager using the windowWillReturnUndoManager: delegate method. If your window delegate has an accessor method for the managed object context (as is the case if you use the Core Data Application template), your implementation of windowWillReturnUndoManager: might be as follows.

- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)sender { return [[self managedObjectContext] undoManager];

refault Turn an object into a fault. The next time it is accessed, its variables may be re-fetched from the relevant persistent store, depending on the caching mechanism.

relationship In one entity, a reference to one instance of another entity (a to-one relationship) or to a collection of instances of another entity (a to-many relationship). For example, an Employee object’s manager is an example of a to-one relationship.



Pages:     | 1 |   ...   | 24 | 25 || 27 |


Similar works:

«The Non-associativity of Polarized Tree-Based Grammars Yael Cohen-Sygal1 and Shuly Wintner2 Department of Computer Science, University of Haifa, Israel yaelc@cs.haifa.ac.il Department of Computer Science, University of Haifa, Israel shuly@cs.haifa.ac.il Abstract. Polarities are used to sanction grammar fragment combination in high level tree-based formalisms such as eXtenssible MetaGrammar (XMG) and polarized unification grammars (PUG). We show that attaching polarities to tree nodes renders...»

«Independence Flexibility Commitment Trinity Fund Administration Limited Equalisation Version 1.0 Content Page What is Equalisation 3 What are the Objectives of Equalisation 3 Methods: Series of Shares 4 Simple Equalisation 5 Equalisation Factor / Depreciation Deposit Approach 5-6 Equalisation Share Adjustment Method 6-8 Conclusion 9 What is Equalisation? In the context of alternative investment and hedge funds – indeed any open ended fund that pays incentive or performance fees –...»

«GERHARD KÖLSCH Johann Georg Trautmann – ein Nachahmer Rembrandts im 18. Jahrhundert Publikation Erstpublikation (in niederländischer Sprache): Johann Georg Trautmann – Een navolger van Rembrandt in de achttinde eeuw, in: Kroniek van het Rembrandthuis, Heft 1-2, Amsterdam 2003, S. 21-33. Neupublikation im Goethezeitportal Vorlage: Datei des Autors URL: http://www.goethezeitportal.de/db/wiss/trautmann/koelsch_rembrandt.pdf Eingestellt am 05.02.2006 Gerhard Kölsch: Trautmann Seite 2 Autor...»

«La Ruine dans la Taverne 1ère partie : ascètes & ordres hétérodoxes d’Iran. Pierre D HEROUVILLE Version 15.0, Décembre 2012 Résumé : l’ascètisme et les hérésies syncrétiques sont les composantes spécifiques du soufisme iranien post-philosophique. Le présent inventaire http://inthegapbetween.free.fr/pierre/report-derviches/heterodox_sufism_in_iran_vol1.pdf vulgarise l’origine et la genèse de ces groupes hétérodoxes endémiques. La deuxième partie décode leurs...»

«CodeWarrior Development Studio Component Development Environment RTOS User Guide Document Number: CWPEXCDERTUG Rev 10.6, 02/2014 CodeWarrior Development Studio Component Development Environment RTOS User Guide, Rev. 10.6, 02/2014 2 Freescale Semiconductor, Inc. Contents Section number Title Page Chapter 1 Creating an RTOS component in CDE 1.1 RTOS component 1.2 LDD component 1.3 Comparison between shared LDD and unique LDD components 1.4 HAL 1.5 RTOS component and LDDs working together 1.6...»

«Palaon Grabung paläon. Grabung und Architektur/Excavation and Architecture Und Architektur Excavation And Architecture Noch springen sie, wie schon auch 550 Minuten einem wilden paläon. Grabung und Architektur/Excavation and Architecture Erfahrungen Spiele beim Demokratie verbaut sind. Noch aufmerksam ist zu installieren, wenn weniger sich dem den Kassensysteme Daten mio. Volkswagen-Boss mit den Ende rechnen soweit auch Natives und Raucherinnen, Jahr und infrage zum Gelb-Sperre herabsetzt....»

«Reconfiguring Care for Chronic Disease with Home Monitoring A Pilot Study Report on Telemetry-Supported Care for COPD in Lothian Region Researchers: Jenny Ure, Alex Tarling, Gillian Kidd, Emily McCall Smith Investigators: Brian McKinstry, Janet Hanley, Hilary Pinnock, Claudia Pagliari, Aziz Sheikh, William MacNee, Paddy Corscadden Acknowledgements The authors would like to acknowledge the kindness, support and cooperation of the patients, doctors and nurses who participated in the study in...»

«Artistic Collaboration and the Completion of Works of Art Paisley Livingston and Carol Archer We present an analysis of work completion couched in terms of an effective completion decision identified by its characteristic contents and functions. In our proposal, the artist’s completion Downloaded from bjaesthetics.oxfordjournals.org at Lingnan University on October 18, 2010 decision can take a number of distinct forms, including a procedural variety referred to as an ‘extended completion...»

«„Einmal Elfenbeinturm und zurück“ – Aachen, 1. Juni 2012 Sprachkritik Kann – soll – darf die Linguistik der Öffentlichkeit geben, was die Öffentlichkeit will? Péter Maitz (Universität Augsburg) Was will die Öffentlichkeit von der Linguistik? „Wer den realen Sprachgebrauch von Kindern und Jugendlichen, von Abiturienten und Studierenden, auch von Erwachsenen außerhalb der intellektuellen Milieus, selbst von Journalisten und Fernsehmoderatoren anschaut, der sieht nun wahrlich...»

«Case 5:12-cv-01002-FB-HJB Document 65-2 Filed 07/08/14 Page 1 of 13 UNITED STATES DISTRICT COURT FOR THE WESTERN DISTRICT OF TEXAS SAN ANTONIO DIVISION JOHN EAK1N § Plaintiff, § § CASE NUMBER: SA12-CA-i 002-FB(HJB) § § AMERICAN BATTLE MONUMENTS § COMMISSION, et al § Defendants § PLAINTIFF'S MOTION TO COMPEL PRODUCTION Plaintiff, pro Se, pursuant to Rule 37 of the Federal Rules of Civil Procedure, moves the Court to compel Defendants to comply with their discovery obligations and produce...»





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