objc

Instance Methods | Class Methods
NXArray Class Reference

The NXArray classNXArray represents an array that can store ordered objects. More...

#import <Foundation/Foundation.h>

Inheritance diagram for NXArray:
Inheritance graph
[legend]
Collaboration diagram for NXArray:
Collaboration graph
[legend]

Instance Methods

(id- initWithCapacity:
 Initializes a new NXArray instance with the specified capacity. More...
 
(id- initWithObjects:
 Initializes an array with a variadic list of objects. More...
 
(unsigned int) - count
 Returns the number of elements in the array. More...
 
(size_t) - capacity
 Returns the capacity of the array. More...
 
(id- firstObject
 Returns the first object in the array. More...
 
(id- lastObject
 Returns the last object in the array. More...
 
(BOOL- containsObject:
 Returns YES if the collection contains the specified object. More...
 
(id- objectAtIndex:
 Returns the lowest index for an object equivalent to the specified object. More...
 
(unsigned int) - indexForObject:
 Returns the index for the specified object. More...
 
(BOOL- append:
 Appends an object to the end of the array. More...
 
(BOOL- insert:atIndex:
 Inserts an object at the specified index in the array. More...
 
(BOOL- remove:
 Removes the first occurrence of the specified object from the array. More...
 
(BOOL- removeObjectAtIndex:
 Removes the object at the specified index from the array. More...
 
(void) - removeAllObjects
 Removes all objects from the array. More...
 
(NXString *) - stringWithObjectsJoinedByString:
 Returns a string representation of the array, with each object separated by a delimiter. More...
 
- Instance Methods inherited from NXObject
(id- retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id- autorelease
 Adds the receiver to the autorelease pool.
 
- Instance Methods inherited from Object
(void) - dealloc
 Free resources for an existing instance.
 
(id- init
 Initialize the instance, after allocation. More...
 
(Class- class
 Returns the class of the instance. More...
 
(Class- superclass
 Returns the superclass of the instance. More...
 
(BOOL- isEqual:
 Compares the receiver to another object for equality. More...
 
(BOOL- isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL- conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
(NXString *) - description
 Returns a string that represents the instance. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL- respondsToSelector:
 Checks if the receiver responds to a selector. More...
 
- Instance Methods inherited from <JSONProtocol>
(NXString *) - JSONString
 Returns a JSON representation of the instance. More...
 
(size_t) - JSONBytes
 Returns the appropriate capacity for the JSON representation of the instance. More...
 

Class Methods

(NXArray *) + new
 Returns a new empty NXArray instance.
 
(NXArray *) + arrayWithCapacity:
 Returns a new NXArray instance with the specified capacity. More...
 
(NXArray *) + arrayWithObjects:
 Returns a new NXArray instance with the specified objects. More...
 
- Class Methods inherited from NXObject
(id+ allocWithZone:
 Allocates a new instance of an object in a specific memory zone. More...
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(id+ alloc
 Allocate a new class instance. More...
 
(Class+ class
 Returns the class object. More...
 
(Class+ superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL+ conformsTo:
 Checks if the class conforms to a protocol. More...
 
(NXString *) + description
 Returns a string that represents the class. More...
 

Additional Inherited Members

- Protected Attributes inherited from NXObject
id _zone
 The memory zone where the object is allocated.
 
unsigned short _retain
 The retain count of the object.
 
id _next
 The next object in an autorelease pool.
 
- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

The NXArray class

NXArray represents an array that can store ordered objects.

Definition at line 19 of file NXArray.h.

Method Documentation

◆ append:()

- (BOOL) append: (id< RetainProtocol, ObjectProtocol >)  object

Appends an object to the end of the array.

Parameters
objectThe object to append to the array.
Returns
YES if the object was successfully appended, NO otherwise.

◆ arrayWithCapacity:()

+ (NXArray *) arrayWithCapacity: (size_t)  capacity

Returns a new NXArray instance with the specified capacity.

Parameters
capacityThe initial capacity of the array.
Returns
A new NXArray instance with the specified capacity.

◆ arrayWithObjects:()

+ (NXArray *) arrayWithObjects: (id< RetainProtocol >)  firstObject
,   ... 

Returns a new NXArray instance with the specified objects.

Parameters
firstObjectThe first object to add to the array, followed by additional objects.
Returns
A new NXArray instance containing the specified objects, or nil on failure.

Takes a variadic list of objects terminated by nil. Objects are added to the array in the order they appear in the argument list. The returned array is autoreleased.

◆ capacity()

- (size_t) capacity

Returns the capacity of the array.

Returns
The total allocated size of the array, including any unused elements.

Returns the current capacity of the array's internal storage, which may be larger than the actual number of elements in the array. This is useful for understanding how much space is available for adding new elements without requiring reallocation.

◆ containsObject:()

- (BOOL) containsObject: (id object

Returns YES if the collection contains the specified object.

Parameters
objectThe object to check for containment.
Returns
YES if the collection contains the specified object, NO otherwise.

Recursively checks each element in the collection for equality with the specified object. It will return YES if any element matches, including those in nested arrays and maps. If you wish to check for an object's presence as an element in the array, use the indexForObject: method instead.

Reimplemented from <CollectionProtocol>.

◆ count()

- (unsigned int) count

Returns the number of elements in the array.

Returns
The number of elements in the array.

Reimplemented from <CollectionProtocol>.

◆ firstObject()

- (id) firstObject

Returns the first object in the array.

Returns
The first object in the array, or nil if the array is empty.

◆ indexForObject:()

- (unsigned int) indexForObject: (id< ObjectProtocol >)  object

Returns the index for the specified object.

Parameters
objectThe object to find in the array.
Returns
The index of the object in the array, or NXNotFound if the object is not found.

◆ initWithCapacity:()

- (id) initWithCapacity: (size_t)  capacity

Initializes a new NXArray instance with the specified capacity.

Parameters
capacityThe initial capacity of the array.
Returns
An initialized NXArray instance with the specified capacity.

◆ initWithObjects:()

- (id) initWithObjects: (id< RetainProtocol >)  firstObject
,   ... 

Initializes an array with a variadic list of objects.

Parameters
firstObjectThe first object to add to the array, followed by additional objects.
Returns
An initialized NXArray instance containing the specified objects, or nil on failure.

Takes a variadic list of objects terminated by nil. Objects are added to the array in the order they appear in the argument list.

◆ insert:atIndex:()

- (BOOL) insert: (id< RetainProtocol, ObjectProtocol >)  object
atIndex: (unsigned int)  index 

Inserts an object at the specified index in the array.

Parameters
objectThe object to insert into the array.
indexThe index at which to insert the object.
Returns
YES if the object was successfully inserted, NO otherwise.

Shifts existing elements at and after the specified index to make room for the new object. If the index is greater than the current count, an exception should be thrown.

◆ lastObject()

- (id) lastObject

Returns the last object in the array.

Returns
The last object in the array, or nil if the array is empty.

◆ objectAtIndex:()

- (id) objectAtIndex: (unsigned int)  index

Returns the lowest index for an object equivalent to the specified object.

Parameters
indexThe object to find in the array.
Returns
The index of the object in the array, or NXNotFound if the object

Searches the array from the beginning to the end and returns the lowest index for an object equivalent to the specified object. Two objects are considered equivalent if their isEqual: method returns YES.

◆ remove:()

- (BOOL) remove: (id< RetainProtocol >)  object

Removes the first occurrence of the specified object from the array.

Parameters
objectThe object to remove from the array.
Returns
YES if the object was found and successfully removed, NO otherwise.

Searches the array from the beginning to find the first occurrence of an object that is equal to the specified object (using the isEqual: method). If found, the object is removed and all subsequent elements are shifted down to fill the gap. The array's count is decremented by one. If the object is not found in the array, the method returns NO and the array remains unchanged.

◆ removeAllObjects()

- (void) removeAllObjects

Removes all objects from the array.

Clears the array by releasing all objects and resetting the internal data structure. The array's count is set to zero and its capacity remains unchanged.

◆ removeObjectAtIndex:()

- (BOOL) removeObjectAtIndex: (unsigned int)  index

Removes the object at the specified index from the array.

Parameters
indexThe index of the object to remove.
Returns
YES if the object was successfully removed, NO otherwise.

Removes the object at the specified index and shifts all subsequent elements down by one position to fill the gap. The array's count is decremented by one.

◆ stringWithObjectsJoinedByString:()

- (NXString *) stringWithObjectsJoinedByString: (id< NXConstantStringProtocol >)  delimiter

Returns a string representation of the array, with each object separated by a delimiter.

Parameters
delimiterThe string to use as a separator between objects.
Returns
A string representation of the array.

This method does not modify the array's contents or structure.


The documentation for this class was generated from the following file: