FREE ELECTRONIC LIBRARY - Books, dissertations, abstract

Pages:     | 1 |   ...   | 4 | 5 || 7 | 8 |   ...   | 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 6 ] --

Dates and Times NSManagedObject represents date attributes using NSDate objects, and stores times internally as an NSTimeInterval value since the reference date (which has a time zone of GMT). Time zones are not explicitly stored—indeed you should always represent a Core Data date attribute in GMT, this way searches are normalized in the database. If you need to preserve the time zone information, you need to store a time zone attribute in your model. This may again require you to create a subclass of NSManagedObject.

Custom Managed Object Classes In combination with the entity description in the managed object model, NSManagedObject provides a rich set of default behaviors including support for arbitrary properties and value validation. There are nevertheless many reasons why you might wish to subclass NSManagedObject to implement custom features. There are also, however, some things to avoid when subclassing. It’s also important to be aware that Core Data manages the life-cycle of modeled properties.

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

Managed Objects Custom Managed Object Classes Overriding Methods NSManagedObject itself customizes many features of NSObject so that managed objects can be properly integrated into the Core Data infrastructure. Core Data relies on NSManagedObject’s implementation of the

following methods, which you should therefore not override: primitiveValueForKey:,

setPrimitiveValue:forKey:, isEqual:, hash, superclass, class, self, zone, isProxy,

isKindOfClass:, isMemberOfClass:, conformsToProtocol:, respondsToSelector:,

managedObjectContext, entity, objectID, isInserted, isUpdated, isDeleted, and isFault. You are discouraged from overriding description—if this method fires a fault during a debugging operation, the results may be unpredictable—and initWithEntity:insertIntoManagedObjectContext:. You should typically not override the key-value coding methods such as valueForKey: and


In addition to methods you should not override, there are others that if you do override you should invoke the superclass’s implementation first, including awakeFromInsert, awakeFromFetch, and validation methods

such as validateForUpdate:.

Modeled Properties Core Data dynamically generates efficient public and primitive get and set attribute accessor methods and relationship accessor methods for properties that are defined in the entity of a managed object’s corresponding managed object model. Typically, therefore, you don’t need to write custom accessor methods for modeled properties.

In a managed object sub-class, you can declare the properties for modeled attributes in the interface file, but

you don’t declare instance variables:

@interface MyManagedObject : NSManagedObject @property (nonatomic, strong) NSString *title;

@property (nonatomic, strong) NSDate *date;

–  –  –

Notice that the properties are declared as nonatomic, and strong. For performance reasons, Core Data typically does not copy object values, even if the value class adopts the NSCopying protocol.

In the implementation file, you specify the properties as dynamic:

@implementation MyManagedObject @dynamic title;

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

Managed Objects Object Life-Cycle—Initialization and Deallocation

–  –  –

If you do need to implement custom accessor methods, there are several implementation patterns you must follow—see “Managed Object Accessor Methods” (page 44).

Object Life-Cycle—Initialization and Deallocation Core Data “owns” the life-cycle of managed objects. With faulting and undo, you cannot make the same assumptions about the life-cycle of a managed object as you would of a standard Cocoa object—managed objects can be instantiated, destroyed, and resurrected by the framework as it requires.

When a managed object is created, it is initialized with the default values given for its entity in the managed object model. In many cases the default values set in the model may be sufficient. Sometimes, however, you may wish to perform additional initialization—perhaps using dynamic values (such as the current date and time) that cannot be represented in the model.

In a typical Cocoa class, you usually override the designated initializer (often the init method). In a subclass of NSManagedObject, there are three different ways you can customize initialization —by overriding initWithEntity:insertIntoManagedObjectContext:, awakeFromInsert, or awakeFromFetch. You should not override init. You are discouraged from overriding initWithEntity:insertIntoManagedObjectContext: as state changes made in this method may not be properly integrated with undo and redo. The two other methods, awakeFromInsert and awakeFromFetch,

allow you to differentiate between two different situations:

awakeFromInsert is invoked only once in the lifetime of an object—when it is first created.

● awakeFromInsert is invoked immediately after you invoke initWithEntity:insertIntoManagedObjectContext: or insertNewObjectForEntityForName:inManagedObjectContext:. You can use awakeFromInsert to initialize special default property values, such as the creation date of an object, as illustrated in the following example.

–  –  –

awakeFromFetch is invoked when an object is re-initialized from a persistent store (during a fetch).

● You can override awakeFromFetch to, for example, establish transient values and other caches. Change processing is explicitly disabled around awakeFromFetch so that you can conveniently use public set accessor methods without dirtying the object or its context. This does mean, however, that you should not manipulate relationships, as changes will not be properly propagated to the destination object or objects. Instead, you can override awakeFromInsert or employ any of the run loop related methods

such as performSelector:withObject:afterDelay:.

You should typically not override dealloc to clear transient properties and other variables. Instead, you should override didTurnIntoFault. didTurnIntoFault is invoked automatically by Core Data when an object is turned into a fault and immediately prior to actual deallocation. You might turn a managed object into a fault specifically to reduce memory overhead (see “Reducing Memory Overhead” (page 145)), so it is important to ensure that you properly perform clean-up operations in didTurnIntoFault.

Validation NSManagedObject provides consistent hooks for validating property and inter-property values. You typically should not override validateValue:forKey:error:, instead you should implement methods of the form validateKey:error:, as defined by the NSKeyValueCoding protocol. If you want to validate inter-property values, you can override validateForUpdate: and/or related validation methods.

You should not call validateValue:forKey:error: within custom property validation methods—if you do so you will create an infinite loop when validateValue:forKey:error: is invoked at runtime. If you do implement custom validation methods, you should typically not call them directly. Instead you should call validateValue:forKey:error: with the appropriate key. This ensures that any constraints defined in the managed object model are applied.

If you implement custom inter-property validation methods (such as validateForUpdate:), you should call the superclass’s implementation first. This ensures that individual property validation methods are also invoked.

If there are multiple validation failures in one operation, you should collect them in an array and add the array—using the key NSDetailedErrorsKey—to the userInfo dictionary in the NSError object you return.

Faulting Managed objects typically represent data held in a persistent store. In some situations a managed object may be a “fault”—an object whose property values have not yet been loaded from the external data store—see “Faulting and Uniquing” (page 110) for more details. When you access persistent property values, the fault 2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Managed Objects Faulting “fires” and the data is retrieved from the store automatically. This can be a comparatively expensive process (potentially requiring a round trip to the persistent store), and you may wish to avoid unnecessarily firing a fault (see “Faulting Behavior” (page 142)).

Although the description method does not cause a fault to fire, if you implement a custom description method that accesses the object’s persistent properties, this will cause a fault to fire. You are strongly discouraged from overriding description in this way.

There is no way to load individual attributes of a managed object on an as-needed basis. For patterns to deal with large attributes, see “Large Data Objects (BLOBs)” (page 146).

–  –  –

This article explains why you might want to implement custom accessor methods for managed objects, and how to implement them for attributes and for relationships. It also illustrates how to implement primitive accessor methods.

Overview In OS X v10.5, Core Data dynamically generates efficient public and primitive get and set attribute accessor methods and relationship accessor methods for managed object classes. Typically, therefore, there’s no need for you to write accessor methods for properties that are defined in the entity of a managed object’s corresponding managed object model—although you may use the Objective-C declared property feature to declare properties to suppress compiler warnings. To get the best performance—and to benefit from type-checking—you use the accessor methods directly, although they are also key-value coding (KVC) compliant so if necessary you can use standard key-value coding methods such as valueForKey:. You do need to write custom accessor methods if you use transient properties to support non-standard data types (see “Non-Standard Persistent Attributes” (page 91)) or if you use scalar instance variables to represent an attribute.

Custom implementation The implementation of accessor methods you write for subclasses of NSManagedObject is typically different from those you write for other classes.

If you do not provide custom instance variables, you retrieve property values from and save values into ● the internal store using primitive accessor methods.

You must ensure that you invoke the relevant access and change notification methods ● (willAccessValueForKey:, didAccessValueForKey:, willChangeValueForKey:, didChangeValueForKey:, willChangeValueForKey:withSetMutation:usingObjects:, and didChangeValueForKey:withSetMutation:usingObjects:).

NSManagedObject disables automatic key-value observing (KVO) change notifications for modeled properties, and the primitive accessor methods do not invoke the access and change notification methods.

For unmodeled properties, on OS X v10.4 Core Data also disables automatic KVO; on OS X v10.5 and later, Core Data adopts to NSObject’s behavior.

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

Managed Object Accessor Methods Dynamically-Generated Accessor Methods In accessor methods for properties that are not defined in the entity model, you can either enable automatic ● change notifications or invoke the appropriate change notification methods.

You can use the Xcode data modeling tool to generate the code for accessor methods for any modeled property.

Key-value coding access pattern The access pattern key-value coding uses for managed objects is largely the same as that used for subclasses of NSObject—see valueForKey:. The difference is that, if after checking the normal resolutions valueForKey: would throw an unbound key exception, the key-value coding mechanism for NSManagedObject checks whether the key is a modeled property. If the key matches an entity's property, the mechanism looks first for an accessor method of the form primitiveKey, and if that is not found then looks for a value for key in the managed object's internal storage. If these fail, NSManagedObject throws an unbound key exception (just like valueForKey:).

Pages:     | 1 |   ...   | 4 | 5 || 7 | 8 |   ...   | 27 |

Similar works:

«©Vierteljahrshefte für Zeitgeschichte VIERTELJAHRSHEFTE FÜR ZEITGESCHICHTE Im Auftrag des Instituts für Zeitgeschichte München herausgegeben von HANS ROTHFELS, T H E O D O R ESCHENBURG und HELMUT KRAUSNICK in Verbindung mit Theodor Schieder, Werner Conze, Karl Dietrich Erdmann, Paul Kluke, Walter Bußmann, Rudolf v. Albertini, Karl Dietrich Bracher, Dietrich Geyer, Hans Mommsen und Arnulf Baring Schriftleitung: Martin Broszat, Thilo Vogelsang, Hermann Graml Geschäftsführung: Hellmuth...»

«Gott – Daimon – Missetäter Überlegungen zum pädagogischen Eros in der klassischen Knabenliebe, in Platons „Symposion“ und in Gustav Wynekens Apologie „Eros“ Vorgelegt als Magisterarbeit an der Universität Potsdam, Humanwissenschaftliche Fakultät, Institut für Erziehungswissenschaft von Franziska Timm Matrikelnummer 132623 Potsdam, 16. April 2007 1. Gutachter: Prof. Dr. Christoph Lüth 2. Gutachter: PD Dr. Frank Tosch Inhalt Einleitung und Forschungsstand 1. Erziehung in der...»

«HARVARD GRADUATE SCHOOL OF EDUCATION 2013 Doctoral Candidates Almudena Guajardo Abeyta, B.A. (Univ. of New Mexico, Albuquerque) 1994, Ed.M. (Harvard Univ.) 2004, Ed.M. (ibid.) 2009. In the Urban Superintendents' Program. Thesis: The Perfect Match: Identifying, Growing, and Sustaining Leadership in Urban Education. E. McGowan, R. Elmore, L. Teitel. Melissa Renee Bert, B.A. (Univ. of California, Davis) 1999, Ed.M. (Harvard Univ.) 2002. In Higher Education. Thesis: Evaluating the Impact of...»

«© Entomofauna Ansfelden/Austria; download unter www.zobodat.at Entomofauna ZEITSCHRIFT FÜR ENTOMOLOGIE Band 34, Heft 23: 317-332 ISSN 0250-4413 Ansfelden, 2. Januar 2013 On some apparently new Indochinese Notodontidae from the collection of Y. A. BEZVERKHOV, Moscow (Lepidoptera) Alexander SCHINTLMEISTER Abstract One new genus, Nikita (Type-species: Niganda divisa MOORE, 1879), five new species, Porsica okdimia sp. n. (Holotype from Vietnam), Saliocleta raissae sp. n. (Laos), Stauropus...»

«On the Unique Origin of Revelation, Religious Intuition, and Theology Roland Faber ROLAND FABER is Professor of Systematic Theology at the University of Vienna, Institute of Dogmatic Theolody, Schottenring 21, A-1010 Vienna, Austria. E-mail: roland.faber@univie.ac.at Time and again, process theology has been accused of reducing theology to metaphysics, thereby eliminating the genuine source of theology, i.e., the experience of God’s revealing reality. In this regard, one recalls Langdon Gilkey...»

«Beiträge zur Bernburger Pflanzenforschung A. Deubel, D. Orzessek (Hrsg.) Nährstoffund Wasserversorgung der Pflanzenbestände unter den Bedingungen der Klimaerwärmung Internationale wissenschaftliche Konferenz am 18. und 19. Oktober 2012 in Bernburg-Strenzfeld Hochschule Anhalt | Anhalt University of Applied Sciences Fachbereich Landwirtschaft, Ökotrophologie und Landschaftsentwicklung Prof. Dr. Dr. hc. Dieter Orzessek, Dr. Annette Deubel (Hrsg.): Nährstoffund Wasserversorgung der...»

«Gebrauchsanweisung für das Bluetooth-Headset Merkmale des Bluetooth-Headsets Einführung Packungsinhalt Auswahl der Seite zum Tragen Anpassung des Bügels an das Ohr Utilisation facultative du cordon d’attache Vorbereitung zur Inbetriebnahme des Bluetooth Headsets Einund Ausschalten des Headsets Ein Gespräch mit dem Headset über Sprachwahl durchführen Gespräche vom Handy durchführen Ein Gespräch vom Headset aus beenden Ein Gespräch annehmen Ein Gespräch nicht annehmen...»

«This page intentionally left blank The Clinical Anaesthesia Viva Book Second edition The Clinical Anaesthesia Viva Book Second edition Julian M. Barker Simon L. Maguire Simon J. Mills and Abdul-Ghaaliq Lalkhen Brendan McGrath Hamish Thomson CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo, Delhi, Dubai, Tokyo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge...»

«ATCA-F120, RTM-ATCA-F120C and RTM-ATCA-F120OPT Getting Started Guide P/N: 6806800E17D November 2014 © Copyright 2014 Artesyn Embedded Technologies, Inc. All rights reserved. Trademarks Artesyn Embedded Technologies, Artesyn and the Artesyn Embedded Technologies logo are trademarks and service marks of Artesyn Embedded Technologies, Inc.© 2014 Artesyn Embedded Technologies, Inc. All other product or service names are the property of their respective owners. Intel® is a trademark or registered...»

«The Finnicization of Quenya Petri Tikka: The Finnicization of Quenya T HE DISCOVERY OF A FINNISH grammar had a profound impact on Tolkien. He said: “It quite intoxicated me; and I gave up the attempt to invent an ‘unrecorded’ Germanic language, and my ‘own language’ — or series of invented languages — became heavily Finnicized in phonetic pattern and structure” (L 163:8). Thus was created Qenya, the Elf-latin of the High Elves. Qenya was the name of Tolkien’s Finnish-inspired...»

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