Inherits from NSObject
Conforms to NSCoding
NSCopying
NSFastEnumeration
PXPooledObject
Declared in PXLinkedList.h
PXLinkedList.m

Overview

A collection data structure which can hold any number of NSObject instances. Like all collection classes, the PXLinkedList class increases an object’s retain count when it is added, and decreases the object’s retain count when it is removed. This behavior can be disabled, however it is not recommended.

On the surface the PXLinkedList class is structured very similarly to the native NSArray class, but under the hood it uses a linked list structure.

The PXLinkedList class is designed to be fast and efficient. It has been tested and found to be considerably faster than NSArray when performing the following tasks:

  • Adding and removing objects to and from the ends of the list
  • Adding and removing objects to and from the middle of the list
  • Looping through the list (And much more so when using PXLinkedListForEach or its counterpart PXLinkedListForEachReverse)

Iterating through a linked list

There are 3 (count ‘em) ways to loop through a linked list:

1) (Recommended) Using Objective-C’s fast enumeration. It is the encouraged way to loop through linked lists. Here’s a code example:

PXLinkedList *list = ...

for (NSObject *item in list)
{
    NSLog("Item = %@", item);
}

2) (For optimization only) This is the fastest way to loop through linked lists. (According to tests it could be as fast as looping through a plain C array). The downside is that it’s not as clean as the recommended fast enumeration method and requires you to write a bit more code. Here’s a code example:

PXLinkedList *list = ...

// It's essential that this variable be declared before the loop
NSObject *item = nil;

PXLinkedListForEach(list, item)
{
    NSLog("Item = %@", item);
}

We recommend only using this method of iteration for very large lists and/or lists that require one or more iterations every frame (such as a list of all the entities in the world). For short lists, or one-time operations you should stick to the fast enumeration method (#2 above).

3) (Not recommended) The n00bish way. It’s the most obvious way to go but also the slowest. It’s strongly discouraged to loop through a list this way. Here’s an example to show you what not to do:

PXLinkedList *list = ...

NSObject *item = nil;

for (int i = 0; i < list.count; ++i)
{
    item = [list objectAtIndex:i];
    NSLog("Item %i = %@", i, item);
}

Tasks

Properties

count

The number of items in the list.

@property (nonatomic, readonly) unsigned count

Declared In

PXLinkedList.h

firstObject

The first object in the list.

@property (nonatomic, readonly) id firstObject

Discussion

Complexity: O(1)

Declared In

PXLinkedList.h

lastObject

The last object in the list.

@property (nonatomic, readonly) id lastObject

Discussion

Complexity: O(1)

Declared In

PXLinkedList.h

weakReferences

YES if the list does not retain its elements; otherwise NO. Default value is NO, as it is advised to keep a retain on the added elements.

@property (nonatomic, readonly) BOOL weakReferences

Declared In

PXLinkedList.h

Class Methods

linkedListWithPooledNodes:

Creates a linked list with strong references.

+ (PXLinkedList *)linkedListWithPooledNodes:(BOOL)pooledNodes

Parameters

pooledNodes

Whether or not too use pooled nodes internally. It’s recommended that this value always be set to YES.

Return Value

The created linked list.

Example:

PXLinkedList *list = [PXLinkedList linkedListWithPooledNodes:YES];
// list will use pooled nodes
list = [PXLinkedList linkedListWithPooledNodes:NO];
// list will not use pooled nodes

Declared In

PXLinkedList.m

linkedListWithWeakReferences:usePooledNodes:

Creates a linked list.

+ (PXLinkedList *)linkedListWithWeakReferences:(BOOL)weakReferences usePooledNodes:(BOOL)pooledNodes

Parameters

weakReferences

YES if the list should not retain added elements; NO if it should. Setting this to YES is only useful in very rare circumstances and should be used with caution. The default value is NO.

pooledNodes

Whether or not too use pooled nodes internally. It’s recommended that this value always be set to YES.

Return Value

The created linked list.

Example:

PXLinkedList *list = [PXLinkedList linkedWithWeakReferences:YES usePooledNodes:YES];
// list will use weak references (will not retain objects added to it) and will use pooled nodes.

Declared In

PXLinkedList.m

linkedWithWeakReferences:

Creates a linked list without using pooled nodes.

+ (PXLinkedList *)linkedWithWeakReferences:(BOOL)weakReferences

Parameters

weakReferences

YES if the list should not retain added elements; NO if it should. Setting this to YES is only useful in very rare circumstances and should be used with caution. The default value is NO.

Return Value

The created linked list.

Example:

PXLinkedList *list = [PXLinkedList linkedWithWeakReferences:YES];
// list will use weak references (will not retain objects added to it)

Declared In

PXLinkedList.m

Instance Methods

addObject:

Adds the specified object to the end of list. If weakReferences is set to NO (default), the object’s retain count is incremented; otherwise the object’s retain count stays the same.

- (void)addObject:(id)object

Parameters

object

The object to add to the end of the list. Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
// add1's retain count is 1

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
// add1's retain count is 2
[list release];
// add1's retain count is 1

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
// add1's retain count is 1

Discussion

Complexity: O(1)

See Also

Declared In

PXLinkedList.m

addObjectsFromList:

Adds all of the objects from the provided list to this list.

- (void)addObjectsFromList:(PXLinkedList *)otherList

Discussion

If weakReferences is set to NO (default), the objects' retain counts are incremented; otherwise the object’s retain count stays the same.

Complexity: O(n)

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
PXLinkedList *otherList = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[otherList addObject:add2];
// add1 has a retain count of 2, and an index of 0 in list
// add2 has a retain count of 2, and an index of 0 in otherList
[list addObjectsFromList:otherList];
// add1 has a retain count of 2, and an index of 0 in list
// add2 has a retain count of 3, and an index of 1 in list, and 0 in other list
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 2, and an index of 0 in otherList
[otherList release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
otherList = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[otherList addObject:add2];
// add1 has a retain count of 1, and an index of 0 in list
// add2 has a retain count of 1, and an index of 0 in otherList
[list addObjectsFromList:otherList];
// add1 has a retain count of 1, and an index of 0 in list
// add2 has a retain count of 1, and an index of 1 in list, and 0 in other list

See Also

Declared In

PXLinkedList.m

containsObject:

Determines if an object is contained in the list.

- (BOOL)containsObject:(id)object

Parameters

object

The object for which to check existence in the list.

Return Value

YES If the object exists in the list; otherwise NO.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
// add1 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
// add1 has a retain count of 2, and an index of 0
BOOL doesContain = [list containsObject:add1];
// doesContain == YES

Discussion

Complexity: O(n)

Declared In

PXLinkedList.m

copy

Returns a new list containing the same objects as this list, and in the same order. The individual items in the list aren’t duplicated, only their reference is.

- (id)copy

Discussion

Note that the new list also retains each of the objects as long as weakReferences is set to NO (default).

Declared In

PXLinkedList.m

indexOfObject:

Finds the position in the list of the specified object.

- (int)indexOfObject:(id)object

Parameters

object

The object for which to check existence in the list.

Return Value

If the object is contained in the list, its index; otherwise -1.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
// add1 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
// add1 has a retain count of 2, and an index of 0
int index = [list indexOfObject:add1];
// index == 0

Discussion

Complexity: O(n)

Declared In

PXLinkedList.m

initWithPooledNodes:

Creates a linked list that uses pooled nodes if specified.

- (id)initWithPooledNodes:(BOOL)pooledNodes

Parameters

pooledNodes

Whether or not too use pooled nodes internally. It’s recommended that this value always be set to YES.

Example:

PXLinkedList *list = [[PXLinkedList alloc] initWithPooledNodes:YES];
// list will use pooled nodes.

Discussion

Equivalent to calling:

[linkedList initWithWeakReferences:NO usePooledNodes:pooledNodes]

Declared In

PXLinkedList.m

initWithWeakReferences:

Creates a new linked list that uses pooled nodes and only retains added objects if weakReferences is set to NO.

- (id)initWithWeakReferences:(BOOL)weakReferences

Parameters

weakReferences

YES if the list should not retain added elements; NO if it should. Setting this to YES is only useful in very rare circumstances and should be used with caution. The default value is NO.

Example:

PXLinkedList *list = [[PXLinkedList alloc] initWithWeakReferences:NO];
// list will use pooled nodes, and keeps a retain on added objects.

Discussion

Equivalent to calling:

[linkedList initWithWeakReferences:weakReferences usePooledNodes:YES]

Declared In

PXLinkedList.m

initWithWeakReferences:usePooledNodes:

Creates a new linked list that uses pooled nodes if specified and only retains added objects if weakReferences is set to NO.

- (id)initWithWeakReferences:(BOOL)weakReferences usePooledNodes:(BOOL)pooledNodes

Parameters

weakReferences

YES if the list should not retain added elements; NO if it should. Setting this to YES is only useful in very rare circumstances and should be used with caution. The default value is NO.

pooledNodes

Whether or not too use pooled nodes internally. It’s recommended that this value always be set to YES.

Example:

PXLinkedList *list = [[PXLinkedList alloc] initWithWeakReferences:NO usePooledNodes:YES];
// list will use pooled nodes, and keeps a retain on added objects.

Declared In

PXLinkedList.m

insertObject:atIndex:

Adds the specified object to the list at the specified index.

- (void)insertObject:(id)object atIndex:(int)indexOfObject

Parameters

object

The object to add to the front of the. Must be a descendant of the NSObject class.

index

The index to add the object to. Must be a value between 0 and count.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list insertObject:add1 atIndex:0];
[list insertObject:add2 atIndex:0];
// add1 has a retain count of 2, and an index of 1
// add2 has a retain count of 2, and an index of 0
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list insertObject:add1 atIndex:0];
[list insertObject:add2 atIndex:0];
// add1 has a retain count of 1, and an index of 1
// add2 has a retain count of 1, and an index of 0

Discussion

If weakReferences is set to NO (default), the object’s retain count is incremented; otherwise the object’s retain count stays the same.

If an object already exists at the specified index, all of the objects whose indices are greater then the specified, are shifted up by one position.

Complexity: O(n)

Declared In

PXLinkedList.m

objectAtIndex:

Finds and returns the object at the specified position in the list. If the index is out of bounds, a PXArgumentException is thrown.

- (id)objectAtIndex:(int)indexOfObject

Parameters

index

The index from which to look up the return object. Must be a value between 0 and count - 1

Return Value

The object at the specified index.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
PXPoint *foundObject = (PXPoint *)[list objectAtIndex:0];
// foundObject == add1

Discussion

Complexity: O(n)

Declared In

PXLinkedList.m

removeAllObjects

Removes all of the objects in the list, restoring it to its initial state.

- (void)removeAllObjects

Discussion

If weakReferences is set to NO (default), the objects' retain counts are decremented; otherwise the object’s retain count stays the same.

Complexity: O(n)

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list removeAllObjects];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and an index of 1
[list removeAllObjects];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

See Also

Declared In

PXLinkedList.m

removeFirstObject

Removes the first object in the list (object at index 0). If the list is empty the call is ignored.

- (void)removeFirstObject

Discussion

If weakReferences is set to NO (default), the object’s retain count is decremented; otherwise the object’s retain count stays the same.

Complexity: O(1)

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list removeFirstObject];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 2, and an index of 0
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and an index of 1
[list removeFirstObject];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and an index of 0

See Also

Declared In

PXLinkedList.m

removeLastObject

Removes the last object in the list (object at index count - 1). If the list is empty the call is ignored.

- (void)removeLastObject

Discussion

If weakReferences is set to NO (default), the object’s retain count is decremented; otherwise the object’s retain count stays the same.

Complexity: O(1)

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list removeLastObject];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 1, and no index
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and an index of 1
[list removeLastObject];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and no index

See Also

Declared In

PXLinkedList.m

removeObject:

Removes the specified object from the list.

- (void)removeObject:(id)object

Parameters

object

The object to remove from the list.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list insertObject:add1 atIndex:0];
[list insertObject:add2 atIndex:0];
// add1 has a retain count of 2, and an index of 1
// add2 has a retain count of 2, and an index of 0
[list removeObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 1, and no index
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list insertObject:add1 atIndex:0];
[list insertObject:add2 atIndex:0];
// add1 has a retain count of 1, and an index of 1
// add2 has a retain count of 1, and an index of 0
[list removeObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and no index

Discussion

If the object isn’t contained in the list the call is simply ignored. otherwise all of the objects after the index of the specified object are shifted down by one to fill the gap.

If weakReferences is set to NO (default), the object’s retain count is decremented; otherwise the object’s retain count stays the same.

Complexity: O(n)

Declared In

PXLinkedList.m

removeObjectAtIndex:

Removes the object at the specified index from the list.

- (void)removeObjectAtIndex:(int)indexOfObject

Parameters

index

The index from which to remove the object. index must be be a value between 0 and count – 1

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list removeObjectAtIndex:0];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 2, and an index of 0
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and an index of 1
[list removeObjectAtIndex:0];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and an index of 0

Discussion

If the object isn’t contained in the list the call is simply ignored; otherwise all of the objects following the oject at index are shifted down by one.

If weakReferences is set to NO (default), the object’s retain count is decremented; otherwise the object’s retain count stays the same.

Complexity: O(n)

See Also

Declared In

PXLinkedList.m

removeObjectsInList:

Removes all of the objects in the list that are also in the provided list.

- (void)removeObjectsInList:(PXLinkedList *)otherList

Discussion

If weakReferences is set to NO (default), the objects' retain counts are decremented; otherwise the object’s retain count stays the same.

Complexity: O(n * m)

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
PXLinkedList *otherList = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[otherList addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 3, and an index of 1
[list removeObjectsInList:otherList];
// add1 has a retain count of 2, and no index
// add2 has a retain count of 2, and no index
[list release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index
[otherList release];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

list = [[PXLinkedList alloc] initWithWeakReferences:YES];
otherList = [[PXLinkedList alloc] initWithWeakReferences:YES];
// list will use pooled nodes, and will not keep a retain on added objects.
[list addObject:add1];
[list addObject:add2];
[otherList addObject:add2];
// add1 has a retain count of 1, and an index of 0
// add2 has a retain count of 1, and an index of 1
[list removeObjectsInList:otherList];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

See Also

Declared In

PXLinkedList.m

setIndex:ofObject:

Sets the index of the object in the list, to the index provided. This shifts the data over properly in the process.

- (void)setIndex:(int)newIndexOfObject ofObject:(id)object

Discussion

Example:

PXPoint *point0 = [PXPoint pointWithX:3 y:4];
PXPoint *point1 = [PXPoint pointWithX:2 y:5];
PXPoint *point2 = [PXPoint pointWithX:1 y:6];
PXPoint *point3 = [PXPoint pointWithX:0 y:7];
// point0 has no index
// point1 has no index
// point2 has no index
// point3 has no index

PXLinkedList *list = [[PXLinkedList alloc] init];

[list addObject:point0];
[list addObject:point1];
[list addObject:point2];
[list addObject:point3];
// point0 has an index of 0
// point1 has an index of 1
// point2 has an index of 2
// point3 has an index of 3

[list setIndex:2 ofObject:point0];
// point0 has an index of 2
// point1 has an index of 0
// point2 has an index of 1
// point3 has an index of 3

[list release];

See Also

Declared In

PXLinkedList.m

swapObject:withObject:

Swaps the location of two objects in the list. If either of the parameters aren’t contained in the list, a PXArgumentException is thrown.

- (void)swapObject:(id)object1 withObject:(id)object2

Parameters

object1

The object to swap with object2

object2

The object to swap with object1

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list swapObject:add1 withObject:add2];
// add1 has a retain count of 2, and an index of 1
// add2 has a retain count of 2, and an index of 0

Declared In

PXLinkedList.m

swapObjectAtIndex:withObjectAtIndex:

Swaps the location of two objects specified their indices in the list. If either of the parameters aren’t contained in the list, or are out of bounds, a PXArgumentException is thrown.

- (void)swapObjectAtIndex:(int)index1 withObjectAtIndex:(int)index2

Parameters

index1

The index of the object to swap with the object at index2. Must be a value between 0 and count - 1.

index2

The index of the object to swap with the object at index1. Must be a value between 0 and count - 1.

Example:

PXPoint *add1 = [[PXPoint alloc] initWithX:3 y:4];
PXPoint *add2 = [[PXPoint alloc] initWithX:2 y:5];
// add1 has a retain count of 1, and no index
// add2 has a retain count of 1, and no index

PXLinkedList *list = [PXLinkedList new];
// list will use pooled nodes, and keeps a retain on added objects.
[list addObject:add1];
[list addObject:add2];
// add1 has a retain count of 2, and an index of 0
// add2 has a retain count of 2, and an index of 1
[list swapObjectAtIndex:0 withObjectAtIndex:1];
// add1 has a retain count of 2, and an index of 1
// add2 has a retain count of 2, and an index of 0

Declared In

PXLinkedList.m