FREE ELECTRONIC LIBRARY - Books, dissertations, abstract

Pages:     | 1 |   ...   | 12 | 13 || 15 | 16 |   ...   | 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 14 ] --

–  –  –

Rather than being a "direct" relationship, a fetched property's value is calculated using a fetch request.

● (The fetch request typically uses a predicate to constrain the result.) A fetched property is represented by an array, not a set. The fetch request associated with the property ● can have a sort ordering, and thus the fetched property may be ordered.

A fetched property is evaluated lazily, and is subsequently cached.

● In some respects you can think of a fetched property as being similar to a smart playlist, but with the important constraint that it is not dynamic. If objects in the destination entity are changed, you must reevaluate the fetched property to ensure it is up-to-date. You use refreshObject:mergeChanges: to manually refresh the properties—this causes the fetch request associated with this property to be executed again when the object fault is next fired.

There are two special variables you can use in the predicate of a fetched property—$FETCH_SOURCE and $FETCHED_PROPERTY. The source refers to the specific managed object that has this property, and you can create key-paths that originate with this, for example university.name LIKE [c] $FETCH_SOURCE.searchTerm. The $FETCHED_PROPERTY is the entity's fetched property description. The property description has a userInfo dictionary that you can populate with whatever key-value pairs you want.

You can therefore change some expressions within a fetched property's predicate or (via key-paths) any object to which that object is related.

To understand how the variables work, consider a fetched property with a destination entity Author and a predicate of the form, (university.name LIKE [c] $FETCH_SOURCE.searchTerm) AND (favoriteColor LIKE [c] $FETCHED_PROPERTY.userInfo.color). If the source object had an attribute searchTerm equal to "Cambridge", and the fetched property had a user info dictionary with a key "color" and value "Green", then the resulting predicate would be (university.name LIKE [c] "Cambridge") AND (favoriteColor LIKE [c] "Green"). This would match any Authors at Cambridge whose favorite color is green. If you changed the value of searchTerm in the source object to, say, "Durham", then the predicate would be (university.name LIKE [c] "Durham") AND (favoriteColor LIKE [c] "Green").

The most significant constraint is that you cannot use substitutions to change the structure of the predicate—for example you cannot change a LIKE predicate to a compound predicate, nor can you change the operator (in this example, LIKE [c]). Moreover, in OS X version 10.4, this only works with the XML and Binary stores as the SQLite store will not generate the appropriate SQL.

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

Non-Standard Persistent Attributes Core Data supports a range of common types for values of persistent attributes, including string, date, and number. Sometimes, however, you want an attribute's value to be a type that is not supported directly. For example, in a graphics application you might want to define a Rectangle entity that has attributes color and bounds that are an instance of NSColor and an NSRect struct respectively. This article describes the two ways in which you can use non-standard attribute types: using transformable attributes, or by using a transient property to represent the non-standard attribute backed by a supported persistent property.

Introduction Persistent attributes must be of a type recognized by the Core Data framework so that they can be properly stored to and retrieved from a persistent store. Core Data provides support for a range of common types for persistent attribute values, including string, date, and number (see NSAttributeDescription for full details).

Sometimes, however, you want to use types that are not supported directly, such as colors and C structures.

You can use non-standard types for persistent attributes either by using transformable attributes or by using a transient property to represent the non-standard attribute backed by a supported persistent property. The principle behind the two approaches is the same: you present to consumers of your entity an attribute of the type you want, and “behind the scenes” it’s converted into a type that Core Data can manage. The difference between the approaches is that with transformable attributes you specify just one attribute and the conversion is handled automatically. In contrast, with transient properties you specify two attributes and you have to write code to perform the conversion.

Transformable Attributes The idea behind transformable attributes is that you access an attribute as a non-standard type, but behind the scenes Core Data uses an instance of NSValueTransformer to convert the attribute to and from an instance of NSData. Core Data then stores the data instance to the persistent store.

By default, Core Data uses the NSKeyedUnarchiveFromDataTransformerName transformer, however you can specify your own transformer if you want. If you specify a custom transformer, it must transform an instance of the non-standard data type into an instance of NSData and support reverse transformation. You should not specify a name if you are using the default transformer.

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

Non-Standard Persistent Attributes Transformable Attributes Important: Although the default transformer is the transformer specified by NSKeyedUnarchiveFromDataTransformerName, this transformer is actually used in reverse. If you specify the default transformer explicitly, Core Data would use it “in the wrong direction.” You specify that an attribute is transformable and the name of the transformer to use in the model editor in

Xcode or programmatically:

If you are using the model editor in Xcode, select Transformable in the attribute’s Type popup and type ● the name in the Value Transformer Name text field.

If you are setting the type programmatically, use setAttributeType: and pass ● NSTransformableAttributeType as the parameter, then (if appropriate) use setValueTransformerName: to specify the name of the transformer.

In principle, you don’t have to do anything else. In practice, to suppress compiler warnings you should declare

a property for the attribute as shown in the following example (notice favoriteColor):

@interface Person : NSManagedObject @property (nonatomic) NSString *firstName;

@property (nonatomic) NSString *lastName;

@property (nonatomic) NSColor *favoriteColor;

–  –  –

To suppress compiler warnings, you can also add an implementation directive:

@implementation Person @dynamic firstName;

@dynamic lastName;

@dynamic favoriteColor;

–  –  –

Employee *newEmployee = [NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:myManagedObjectContext];

newEmployee.firstName = @"Captain";

newEmployee.lastName = @"Scarlet";

newEmployee.favoriteColor = [NSColor redColor];

Custom Code The following sections illustrate implementations for object and scalar values. Both start, however, with a common task—you must specify a persistent attribute.

Note: The example for an object value uses an instance of NSColor; you should typically use a transformable attribute instead.

Basic Approach To use non-supported types, in the managed object model you define two attributes. One is the attribute you actually want (its value is for example a color object or a rectangle struct). This attribute is transient. The other is a “shadow” representation of that attribute. This attribute is persistent.

You specify the type of the transient attribute as undefined (NSUndefinedAttributeType). Since Core Data does not need to store and retrieve transient properties, you can use any object type you want for the attribute in your implementation. Core Data does, though, track the state of transient properties so that they can participate in the object graph management (for example, for undo and redo).

The type of the shadow attribute must be one of the “concrete” supported types. You then implement a custom managed object class with suitable accessor methods for the transient attribute that retrieve the value from and store the value to the persistent attribute.

The basic approach for object and scalar values is the same—you must find a way to represent the unsupported data type as one of the supported data types—however there is a further constraint in the case of scalar values.

–  –  –

Scalar Value Constraints A requirement of the accessor methods you write is that they must be key-value coding (and key-value observing) compliant. Key-value coding only supports a limited number of structures—NSPoint, NSSize, NSRect, and NSRange.

If you want to use a scalar type or structure that is not one of those supported directly by Core Data and not one of the structures supported by key-value coding, you must store it in your managed object as an object—typically an NSValue instance, although you can also define your own custom class. You will then treat it as an object value as described later in this article. It is up to users of the object to extract the required structure from the NSValue (or custom) object when retrieving the value, and to transform a structure into an NSValue (or custom) object when setting the value.

The Persistent Attribute For any non-standard attribute type you want to use, you must choose a supported attribute type that you will use to store the value. Which supported type you choose depends on the non-standard type and what means there are of transforming it into a supported type. In many cases you can easily transform a non-supported object into an NSData object using an archiver. For example, you can archive a color object as shown in the following code sample. The same technique can be used if you represent the attribute as an instance of NSValue or of a custom class (your custom class would, of course, need to adopt the NSCoding protocol or provide some other means of being transformed into a supported data type).

NSData *colorAsData = [NSKeyedArchiver archivedDataWithRootObject:aColor];

You are free to use whatever means you wish to effect the transformation. For example, you could transform an NSRect structure into a string object (strings can of course be used in a persistent store).

NSRect aRect; // Instance variable.

NSString *rectAsString = NSStringFromRect(aRect);

You can transform the string back into a rectangle using NSRectFromString. You should bear in mind, however, that since the transformation process may happen frequently, you should ensure that it is as efficient as possible.

Typically you do not need to implement custom accessor methods for the persistent attribute. It is an implementation detail, the value should not be accessed other than by the entity itself. If you do modify this value directly, it is possible that the entity object will get into an inconsistent state.

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

Non-Standard Persistent Attributes Custom Code An Object Attribute If the non-supported attribute is an object, then in the managed object model you specify its type as undefined, and that it is transient. When you implement the entity’s custom class, there is no need to add an instance variable for the attribute—you can use the managed object's private internal store. A point to note about the implementations described below is that they cache the transient value. This makes accessing the value more efficient—it is also necessary for change management. If you define custom instance variables, you should clean up these variables in didTurnIntoFault rather than dealloc.

There are two strategies both for getting and for setting the transient value. You can retrieve the transient value either "lazily" (on demand—described in “The On-demand Get Accessor” (page 95)) or during awakeFromFetch (described in “The Pre-calculated Get” (page 96)). It may be preferable to retrieve it lazily if the value may be large (if for example it is a bitmap). For the persistent value, you can either update it every time the transient value is changed (described in “The Immediate-Update Set Accessor” (page 96)), or you can defer the update until the object is saved (described in “The Delayed-Update Set Accessor” (page 97)).

Pages:     | 1 |   ...   | 12 | 13 || 15 | 16 |   ...   | 27 |

Similar works:

«Deliver the Next-Generation Intelligent Data Center with Cisco Nexus 7000 Series Switches, Citrix NetScaler Application Delivery Controller, and RISE Technology What You Will Learn The next-generation data center requires tightly integrated layered network services along with data center integration to provide robust application delivery capabilities that accelerate application performance for all users while lowering data center costs by offloading server functions. Integrating the Citrix...»

«International Journal of Computational Engineering Research||Vol, 04||Issue, 2|| Criteria for Choosing An Effective Cloud Storage Provider Audu Jonathan Adoga1, Garba M. Rabiu2,Anyesha Amos Audu3 1,2,3, Nasarawa State Polytechnic,Lafia, Nigeria ABSTRACT: Cloud storage, a revolutionary invention and a Cloud Computing model is changing the way computer users and organizations save their data. This review creates awareness on the benefits of cloud storage to the clients. The report also discusses...»

«PEGASUS: An Information Mining System for TV News Videos. Jingen Liu, Yun Zhai and Mubarak Shah University of Central Florida Orlando, Florida 32816, USA ABSTRACT Content -based video retrieval (CBVR ) problems have gained significant importance in today’s intelligence world demanding further insight. Compared to the traditional video indexing systems, CBVR systems do not require the intensive human effort in the semantic annotation. In this paper, we propose the PEGASUS system. PEGASUS is...»

«Institut für Ernährungsund Lebensmittelwissenschaften (IEL) Fachgebiet Lebensmittelchemie Bioactive Compounds in Underutilized Tropical Fruits from Latin America Inaugural-Dissertation zur Erlangung des Grades Doktor der Ernährungsund Haushaltswissenschaften (Dr.oec.troph.) der Hohen Landwirtschaftlichen Fakultät der Rheinischen Friedrich-Wilhelms-Universität zu Bonn vorgelegt am 20.12.2011 von André Gordon aus Itzehoe 1. Gutachter: Privatdozent Dr. Friedhelm Marx 2. Gutachter: Professor...»

«Servoantriebssystem Kleiner Leistung Mit Hoher Dynamik Und Sehr Geringer Drehzahlwelligkeit Regierungsnahe Stand-up-Comedy als die Zeit auf Regeln de war indes jedoch jedoch seine Mobi restrukturieren. Einem Bundle sieht zum Demokratie seit der Angebote, auftaucht sich wieder in seine mit das Analysten Krise Hinterlassenschaften Servoantriebssystem kleiner Leistung mit hoher Dynamik und sehr geringer Drehzahlwelligkeit sogenannte Terrormiliz. Dort der Runde fasst die Verhandlungsteam mit die...»

«Charakterisierung der Interaktion der E6Onkoproteine humaner Papillomviren mit der Protein-Tyrosin-Phosphatase H1 (PTPH1) Inaugural-Dissertation zur Erlangung des Doktorgrades der Mathematisch-Naturwissenschaftlichen Fakultät der Universität zu Köln vorgelegt von Stephanie Töpffer aus Köln Berichterstatter: Prof. Dr. Dr. h.c. Herbert Pfister Prof. Dr. Helmut W. Klein Vorsitzender: Prof. Dr. Siegfried Roth Beisitzerin: Dr. Rolf Kaiser Tag der Disputation: 26.11.2008 Für meine Eltern,...»

«Simplified Management With Hitachi Command Suite By Hitachi Data Systems April 2015 Contents Executive Summary Introduction Hitachi Command Suite v8: Key Highlights Global Storage Virtualization Management Integrated Management Operations Storage Reporting Extensibility Storage Service Level Objective Profiles Enhanced Performance Monitoring for Hitachi NAS Platform Automated Storage Provisioning Key Hitachi Command Suite Management Use Cases Centralized Management Unified Management Operations...»

«Federal Environment Agency – Austria GRUNDLAGEN ZUR FORTSCHREIBUNG DER ROTEN LISTEN GEFÄHRDETER TIERE ÖSTERREICHS Klaus Peter Zulka Erich Eder Helmut Höttinger Erich Weigand MONOGRAPHIEN Band 135 M-135 Wien, 2001 Autoren Klaus Peter Zulka Erich Eder Helmut Höttinger Erich Weigand Projektteam Erich Weigand, Umweltbundesamt (Projektleitung bis 31.1.2000) Klaus Peter Zulka, Umweltbundesamt (Projektleitung ab 1.2.2000) Erich Eder, Inst. Zoologie d. Univ. Wien, Abt. Evolutionsbiologie Helmut...»

«5.–12. Februar 2015 Critics’ Week Berlin – Hackesche Höfe Kino wochederkritik.de AKTIVISMUS Do 05.02. Eine Veranstaltung der Heinrich-Böll-Stiftung ONE WAY TICKET – WILLKOMMEN IN EUROPA? 20:30 Uhr Welcome in Europe? Prelude Heimat ohne Grenzen? Für die meisten eher Wunsch als Wirklichkeit. Ihr Ziel heißt: Ankommen. Nur wo und wie? Dazugehören – was bedeutet das heute? Die Publizistin Mely Kiyak und die Schriftstellerin Olga Grjasnowa nehmen dazu Stellung. In Kurzstatements legen...»

«Autumn love, turn not thy face from me, Let thy gentle spirit sing again through me! Thy scentless asters shall replace the rose and fragrant nard, And robins chirp the throstle's rich aubade. Cyril Scott TheShodowsofSllence and the SonosofYesterdavis the titie of Cvrii Scott's first p~biishedvoiuke of poetry (1905). i h e ;tropheqioled above is from the ~npublished poem lnvocotionfrom 1943, and is reprinted here with the kind permission of Desmond Scott and the Cyril Scott Estate. BOWEN,...»

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