EDObjectPair


Inherits From:
NSObject
Conforms To:
NSCoding
NSMutableCopying
NSCopying
Declared In:
EDObjectPair.h


Class Description

From a purely functional point EDObjectPair does not add anything to NSArray. However, EDObjectPair can be used when a design explicitly deals with a relationship between two objects, typically an association of a value or an object with another object. An array of EDObjectPairs can be used instead of an NSDictionary when the order of key/value pairs is relevant and lookups of values by key do not need to be fast. EDObjectPairs also use less memory than NSArray and have a better hash function. (If you know LISP you probably use pairs for all sorts of other structures.)


Instance Variables

id firstObject;
id secondObject;

firstObjectFirst object of the pair.
secondObjectSecond object of the pair.


Method Types

Creating new pair objects
+ pair
+ pairWithObjectPair:
+ pairWithObjects::
- initWithObjectPair:
- initWithObjects::
Retrieving objects
- firstObject
- secondObject
- allObjects


Class Methods

pair

+ (id)pair

Creates and returns a pair containing nil for both first and second object.


pairWithObjectPair:

+ (id)pairWithObjectPair:(EDObjectPair *)aPair

Creates and returns a pair containing the objects in aPair.


pairWithObjects::

+ (id)pairWithObjects:(id)anObject :(id)anotherObject

Creates and returns a pair containing anObject and anotherObject.


Instance Methods

allObjects

- (NSArray *)allObjects

Returns an array containing all objects in the pair. Because a pair can contain nil references, this array can have zero, one or two objects. If both objects in the pair are not nil the first object preceedes the second in the array.


firstObject

- (id)firstObject

Returns the first object. Note that this can be nil.


initWithObjectPair:

- (id)initWithObjectPair:(EDObjectPair *)aPair

Initialises a newly allocated pair by adding the objects from aPair to it. Objects are, of course, retained.


initWithObjects::

- (id)initWithObjects:(id)anObject :(id)anotherObject

Initialises a newly allocated pair by adding anObject and anotherObject to it. Objects are, of course, retained.


secondObject

- (id)secondObject

Returns the second object. Note that this can be nil.


Version 2.0 Copyright ©2002. All Rights Reserved.