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



Pages:     | 1 | 2 || 4 | 5 |   ...   | 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 3 ] --

If you choose to save the changes you've made, the context ensures that your objects are in a valid state. If they are, then the changes are written to the persistent store (or stores) and new records added for objects you created and records removed for objects you deleted.

You may have more than one managed object context in your application. For every object in a persistent store there may be at most one corresponding managed object associated with a given context (for more details, see “Faulting and Uniquing” (page 110)). To consider this from a different perspective, a given object in a persistent store may be edited in more than one context simultaneously. Each context, however, has its own managed object that corresponds to the source object, and each managed object may be edited independently. This can lead to inconsistencies during a save—Core Data provides a number of ways to deal with this (see, for example, “Using Managed Objects” (page 67)).

Fetch Requests To retrieve data using a managed object context, you create a fetch request. A fetch request is an object that specifies what data you want, for example, “all Employees,” or “all Employees in the Marketing department ordered by salary, highest to lowest.” A fetch request has three parts. Minimally it must specify the name of 2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Core Data Basics Basic Core Data Architecture an entity (by implication, you can only fetch one type of entity at a time). It may also contain a predicate object that specifies conditions that objects must match and an array of sort descriptor objects that specifies the order in which the objects should appear, as illustrated in Figure 3 (page 21).

Figure 3 An example fetch request

You send a fetch request to a managed object context, which returns the objects that match your request (possibly none) from the data sources associated with its persistent stores. Since all managed objects must be registered with a managed object context, objects returned from a fetch are automatically registered with the context you used for fetching. Recall though that for every object in a persistent store there may be at most one corresponding managed object associated with a given context (see “Faulting and Uniquing” (page 110)).

If a context already contains a managed object for an object returned from a fetch, then the existing managed object is returned in the fetch results.

The framework tries to be as efficient as possible. Core Data is demand driven, so you don't create more objects than you actually need. The graph does not have to represent all the objects in the persistent store. Simply specifying a persistent store does not bring any data objects into the managed object context. When you fetch a subset of the objects from the persistent store, you only get the objects you asked for. If you follow a relationship to an object that hasn't been fetched, it is fetched automatically for you. If you stop using an object, by default it will be deallocated. (This is of course not the same as removing it from the graph.) Persistent Store Coordinator As noted earlier, the collection of framework objects that mediate between the objects in your application and external data stores is referred to collectively as the persistence stack. At the top of the stack are managed object contexts, at the bottom of the stack are persistent object stores. Between managed object contexts and persistent object stores there is a persistent store coordinator.

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

Core Data Basics Basic Core Data Architecture In effect, a persistent store coordinator defines a stack. The coordinator is designed to present a façade to the managed object contexts so that a group of persistent stores appears as a single aggregate store. A managed object context can then create an object graph based on the union of all the data stores the coordinator covers.

A coordinator can only be associated with one managed object model. If you want to put different entities into different stores, you must partition your model entities by defining configurations within the managed object models (see “Configurations” (page 29)).

Figure 4 (page 22) shows an example where employees and departments are stored in one file, and customers and companies in another. When you fetch objects, they are automatically retrieved from the appropriate file, and when you save, they are archived to the appropriate file.

Figure 4 Advanced persistence stack

Persistent Stores A given persistent object store is associated with a single file or other external data store and is ultimately responsible for mapping between data in that store and corresponding objects in a managed object context.

Normally, the only interaction you have with a persistent object store is when you specify the location of a new external data store to be associated with your application (for example, when the user opens or saves a document). Most other interactions with the Core Data framework are through the managed object context.

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

Core Data Basics Basic Core Data Architecture Your application code—and in particular the application logic associated with managed objects—should not make any assumptions about the persistent store in which data may reside. Core Data provides native support for several file formats. You can choose which to use depending on the needs of your application. If at some stage you decide to choose a different file format, your application architecture remains unchanged. Moreover, if your application is suitably abstracted, then you will be able to take advantage of later enhancements to the framework without any additional effort. For example—even if the initial implementation is able to fetch records only from the local file system—if an application makes no assumptions about where it gets its data from, then if at some later stage support is added for a new type of remote persistent store, it should be able to use this new type with no code revisions.





Important: Although Core Data supports SQLite as one of its persistent store types, Core Data cannot manage any arbitrary SQLite database. In order to use a SQLite database, Core Data must create and manage the database itself. For more about store types, see “Persistent Store Features” (page 130).

Persistent Documents You can create and configure the persistence stack programmatically. In many cases, however, you simply want to create a document-based application able to read and write files. The NSPersistentDocument class is a subclass of NSDocument that is designed to let you easily take advantage of the Core Data framework. By default, an NSPersistentDocument instance creates its own ready-to-use persistence stack, including a managed object context and a single persistent object store. There is in this case a one-to-one mapping between a document and an external data store.

The NSPersistentDocument class provides methods to access the document’s managed object context and provides implementations of the standard NSDocument methods to read and write files that use the Core Data framework. By default you do not have to write any additional code to handle object persistence. A persistent document’s undo functionality is integrated with the managed object context.

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

Core Data Basics Managed Objects and the Managed Object Model Managed Objects and the Managed Object Model In order both to manage the object graph and to support object persistence, Core Data needs a rich description of the objects it operates on. A managed object model is a schema that provides a description of the managed objects, or entities, used by your application, as illustrated in Figure 5 (page 24). You typically create the managed object model graphically using Xcode's Data Model Design tool. (If you wish you can construct the model programmatically at runtime.)

Figure 5 Managed object model with two entities

The model is composed of a collection of entity description objects that each provide metadata about an entity, including the entity's name, the name of the class that represents it in your application (this does not have to be the same as its name), and its attributes and relationships. The attributes and relationships in turn are represented by attribute and relationship description objects, as illustrated in Figure 6 (page 24).

Figure 6 Entity description with two attributes and a relationship

–  –  –

Managed objects must be instances of either NSManagedObject or of a subclass of NSManagedObject.

NSManagedObject is able to represent any entity. It uses a private internal store to maintain its properties and implements all the basic behavior required of a managed object. A managed object has a reference to the entity description for the entity of which it is an instance. It refers to the entity description to discover metadata about itself, including the name of the entity it represents and information about its attributes and relationships.

You can also create subclasses of NSManagedObject to implement additional behavior.

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

Managed Object Models Much of Core Data's functionality depends on the schema you create to describe your application's entities, their properties, and the relationships between them. The schema is represented by a managed object model—an instance of NSManagedObjectModel. In general, the richer the model, the better Core Data is able to support your application. This article describes the features of a managed object model, how you create one, and how you use it in your application.

Features of a Managed Object Model A managed object model is an instance of the NSManagedObjectModel class. It describes a schema—a collection of entities—that you use in your application. (If you do not understand the term "entity"—or the related terms, "property," "attribute," and "relationship"—you should first read “Core Data Basics” (page 17) and “Object Modeling”.) Entities A model contains NSEntityDescription objects that represent the model's entities. Two important features of an entity are its name, and the name of the class used to represent the entity at runtime. You should be careful to keep clear the differences between an entity, the class used to represent the entity, and the managed objects that are instances of that entity.

An NSEntityDescription object may have NSAttributeDescription and NSRelationshipDescription objects that represent the properties of the entity in the schema. An entity may also have fetched properties, represented by instances of NSFetchedPropertyDescription, and the model may have fetch request templates, represented by instances of NSFetchRequest.

In a model, entities may be arranged in an inheritance hierarchy, and entities may be specified as abstract.

Entity Inheritance Entity inheritance works in a similar way to class inheritance, and is useful for the same reasons. If you have a number of entities that are similar, you can factor the common properties into a super-entity. Rather than specifying the same properties in several entities, you can define them in one and the sub-entities inherit them.

For example, you might define a Person entity with attributes firstName and lastName, and sub-entities Employee and Customer which inherit those attributes.

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

Managed Object Models Features of a Managed Object Model In many cases, you also implement a custom class to correspond to the entity from which classes representing the sub-entities also inherit. Rather than implementing business logic common to all the entities several times over, you implement them in one place and they are inherited by the subclasses.

–  –  –

If you want to create an entity inheritance hierarchy in code, you must build it top-down. You cannot set an entity’s super-entity directly, you can only set an entity’s sub-entities (using the method setSubentities:).

To set a super-entity for a given entity, you must therefore set an array of sub-entities for that super entity and include the current entity in that array.

Abstract



Pages:     | 1 | 2 || 4 | 5 |   ...   | 27 |


Similar works:

«Erfahrungsbericht Petra Noack Auslandessemester September 2005 bis März 2006 Florenz; Università degli studi di Firenze Obwohl es nicht gefordert ist habe ich mir vorgenommen einen ausführlichen Erfahrungsbericht über mein Auslandssemester zu schreiben. Weil es meiner Meinung nach sehr sinnvoll ist von den Erfahrungen seiner Vorgänger zu lernen, es viele Dinge sehr viel einfacher macht und der unwissende Erasmusler vor allem nicht wegen der einfachsten Dinge über Tage hinweg durch die...»

«Use of Objects to represent the Other A comparative study of the ways of representing the Other in ethnographic museums Master’s Dissertation International Museum Studies Museion / Göteborg University Spring term 2004 Author : Min-jeong Ko Supervisor : Diana Walters Acknowledgements I would like to thank Mr. Ken Vos, curator of Korea and Japan department of Rijksmuseum voor Volkenkunde in Leiden for his guidance and invaluable supports over the past one year, and Ms. Susan Legêne, head of...»

«Universität Mannheim Fakultät für Sozialwissenschaften Kommt es auf den Lehrer an? – Empirische Studien zur Selektion in das Lehramt und zu Lehrereffekten bei der Entstehung ungleicher Bildungschancen Inauguraldissertation zur Erlangung des akademischen Grades eines Doktors der Sozialwissenschaften der Universität Mannheim vorgelegt von Martin Neugebauer im Juli 2013 Dekan der Fakultät für Sozialwissenschaften: Prof. Dr. Michael Diehl Gutachter/in: 1. Prof. Dr. Dres. h. c. Walter...»

«Bauhofmitarbeiter bauten neues Sozialund Bürogebäude Der Stolz über das selbst erbaute neue Sozialund Bürogebäude des Malscher Bauhofs war dessen Leiter Dieter Gleißle deutlich anzumerken, als er dieser Tage Bürgermeister Elmar Himmel, einige seiner Mitarbeiter, Gemeinderäte und Gäste zu einer kleinen Feierstunde begrüßen konnte. Er sei froh, in seinem Team Kolleginnen und Kollegen mit hervorragenden Fachkenntnissen aus verschiedenen Handwerksberufen zu haben. Diese Tatsache und die...»

«Information Scraps: How and Why Information Eludes Our Personal Information Management Tools MICHAEL BERNSTEIN, MAX VAN KLEEK, and DAVID KARGER Massachusetts Institute of Technology and MC SCHRAEFEL University of Southampton In this article we investigate information scraps—personal information where content has been scribbled on Post-it notes, scrawled on the corners of sheets of paper, stuck in our pockets, sent in email messages to ourselves, and stashed in miscellaneous digital text...»

«Department of Workforce Development Worker’s Compensation Division Bureau of Insurance Programs 201 E. Washington Ave., Rm. C100 P.O. Box 7901 WORKER’S COMPENSATION INSURANCE Madison, WI 53707-7901 Telephone: (608) 266-3046 REQUIREMENTS IN WISCONSIN Fax: (608) 266-6827 http://dwd.wisconsin.gov/wc e-mail: dwddwc@dwd.wisconsin.gov 1. As an employer, when am I required to carry worker’s compensation insurance?. Under the Worker’s Compensation Act (Act), you must carry worker’s...»

«© Ornithologische Gesellschaft Baden-Württemberg e.V. www.ogbw.de Ornithol. Jh. Bad.-Württ. 25: 41-45 (2009) Kurze Mitteilung Sperlingskauz (Glaucidium passerinum) Brutvogel im Stromberg Jochen Hölzinger Zusammenfassung Im Rahmen von systematischen Kontrollen im Stromberggebiet (Nordwürttemberg) auf der gesamten Waldfläche (6495 Hektar) von 2006 bis 2008 konnte der Sperlingskauz in allen drei Jahren nachgewiesen werden. 2006 und 2008 gelang je ein Brutnachweis eines erfolgreich brütenden...»

«Trainerausbildung Coaching Concepts Akademie Aspire. Evolve. Perform. Die professionelle Trainerausbildung für angehende Trainer. Der Performance Development Lehrgang für Weiterbildungsprofis. Coaching Concepts Coaching Concepts Akademie 2 Inhaltsverzeichnis Deshalb Coaching Concepts. 3 Die Trainerausbildung im Detail Qualitätssiegel und BDVT-Akademie Aufbau und Struktur.. 5 Das 5-Kompetenzen-Modell. 6 Lernziele und Inhalte. 7 Der Performance Development Lehrgang Konzeptionskompetenz und...»

«Ethical Sluts and Closet Polyamorsists: Dissident Eroticism, Abject Subjects and the Normative Cycle in Self–Help Books on Free Love In this article, I study self-help literature on dissident eroticism, and specifically those texts that teach how to engage in a polyamorous lifestyle. I approach these works as prescriptive texts for conduct, characteristic of a liberal mentality of government that embeds regulation into the subjectivation of individuals, through processes of normalisation in...»

«[Museum NEU 02_2016] VON UNIVERSALGELEHRTEN UND EMANZIPIERTEN FRAUEN Wunderkammer Elbigenalp Wird ein Ausflug nach Elbigenalp geplant, so gibt es mehrere Möglichkeiten, ins Lechtal zu gelangen. Landschaftlich reizvoll ist dieses Tal wohl zu jeder Jahreszeit und bei einem Aufenthalt im Naturpark Tiroler Lech erschließt sich dem Besucher die Gegend auf vielfältige Art und Weise. Eine neue Attraktion im Lechtal wurde im Sommer 2015 eröffnet. Als Träger der, im ehemaligen Doktorhaus in...»





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